我正在处理如何向jquery的iframe post表单插件发送成功的响应。
在插件演示的源代码的帮助下,我可以看到下面的代码:(点击这里获取源)
complete : function (response)
{
var style,
width,
html = '';
if (!response.success)
// I've always came to this block! And that is exactly the problem that I have
{
$('.message').slideUp(function ()
{
$(this)
.html('There was a problem with the image you uploaded')
.css({
color : '#9c0006',
background : '#ffc7ce',
borderColor : '#9c0006'
})
.slideDown();
});
}
else /***** When is the response successful and when will code come here? *****/
{
/*
following code goes here...
*/
}
}确切的问题是,response.success什么时候才是真的?如何使用PHP将其设置为TRUE?(请同时回答是否带有JSON风格)
发布于 2013-07-24 23:56:31
当您运行ajax并与php通信时。您将获取任何php回音,并使用它。在这种情况下,使用json编码可能是最明智的。这里有一个非常基本的例子来给你一个想法。
php文件:
echo json_encode(array('success' => true));现在是一个基本的ajax请求
$.ajax({url:"ajax.php",success:function(result){
result = $.parseJSON(result); // we do this to convert the php into javascript format
if(result.success){
alert('this is true');
}
}});https://stackoverflow.com/questions/17846274
复制相似问题