我正在处理如何向jquery's iframe post form plugin发送成功的回复。
借助插件演示的源代码,我可以看到下面的代码如下:(Click here for source)
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
样式)
答案 0 :(得分:0)
当你运行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');
}
}});