正在向jquery发送成功响应';s(iframepost-form)插件


Sending successfull response to jquery's (iframe-post-form) plugin

我正在处理如何将成功响应发送到jquery的iframe post-form插件

在插件演示的源代码的帮助下,我可以看到以下代码:(点击此处获取源代码)

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样式)

当您运行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');
     }
}});