user198729
user198729

Reputation: 63626

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.

Upvotes: 0

Views: 2353

Answers (3)

Marc Overflow
Marc Overflow

Reputation: 1

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

Upvotes: 0

hitautodestruct
hitautodestruct

Reputation: 20820

As of PHP 5.4.0 you can use http_response_code():

<?php http_response_code(200); ?>

Upvotes: 1

echo
echo

Reputation: 7845

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.

Upvotes: 2

Related Questions