首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >发送对jquery(iframe-post)插件的成功响应

问发送对jquery(iframe-post)插件的成功响应
EN

Stack Overflow用户
提问于 2013-07-24 23:02:36
回答 1查看 762关注 0票数 0

我正在处理如何向jquery的iframe post表单插件发送成功的响应。

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

代码语言:javascript
复制
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风格)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-24 23:56:31

当您运行ajax并与php通信时。您将获取任何php回音,并使用它。在这种情况下,使用json编码可能是最明智的。这里有一个非常基本的例子来给你一个想法。

php文件:

代码语言:javascript
复制
echo json_encode(array('success' => true));

现在是一个基本的ajax请求

代码语言:javascript
复制
$.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');
     }
}});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17846274

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档