简体   繁体   中英

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/questions/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.

从PHP 5.4.0开始,您可以使用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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM