首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何将php立即发送到ajax?

如何将php立即发送到ajax?
EN

Stack Overflow用户
提问于 2018-08-21 05:14:03
回答 2查看 0关注 0票数 0

我使用jquery的ajax来调用php api:

$.ajax({
            type:"POST",
            dataType:"json",
            data:{type:type,fid:fid,model:'star'},
            url:'Recommend/Star/mark',
            success:function (data) {
                //do something
            },
        ...
      });

Recommend/Star/mark方法中的PHP代码:

    error_reporting(0);
    set_time_limit(0);
    ob_implicit_flush(true);
    ob_end_clean();

    ob_start ();
    echo json_encode($boolMark);
    ob_flush();
    flush();

    sleep(3);
    $this->afterMark($uid, $fid);

我想立即向ajax发送php echo结果,但我的代码不起作用。

如何让php立即将结果发送到ajax,并继续执行剩余的代码?

EN

Stack Overflow用户

发布于 2018-08-21 13:41:23

 ....
 echo json_encode($boolMark . "<br>\n");
 // get the size of the output
 $size = ob_get_length();
 // send headers to tell the browser to close the connection
 header("Content-Length: $size");
 header('Connection: close');
 ob_end_flush();
 ob_flush();
 flush();
 /******** background process starts here ********/

 ignore_user_abort(true);

 /******** background process ********/
 set_time_limit(0); //no time limit

 /******** Rest of your code starts here ********/
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100002323

复制
相关文章

相似问题

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