开发者

How to return a 200 ok status programmatically to ajax request in PHP?

I ask this question for the comment of this answer:

https://serverfault.com/quest开发者_开发技巧ions/104648/is-this-http-servers-issue/104679#104679

EDIT

I missed an important point,should also keep the connection not closed.

You guys can smell I'm trying to figure out how long polling actually works.


200 OK happens as long as nothing goes wrong. So you should always get that status as long as the HTTP request succeeds. No need to do anything special.


As of PHP 5.4.0 you can use http_response_code():

<?php http_response_code(200); ?>


to complete hitautodestruc post, with PHP <5.4 you could also set

<?php header("HTTP/1.1 200 OK"); ?>

..but sending 200 code in any way is useless, since it is already sent by default when request completes, and if none error occurs otherwise on server-side (5xx)

maybe you are looking for something like this ?

HTTP/1.1 206    Partial Content
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜