如何以编程方式向 PHP 中的 ajax 请求返回 200 ok 状态?

发布于 2024-08-18 18:49:09 字数 303 浏览 3 评论 0原文

我问这个问题是为了对此答案的评论:

https://serverfault.com /questions/104648/is-this-http-servers-issue/104679#104679

编辑

我错过了重要的一点,还应该保持连接不关闭。

你们可以闻到我正在尝试找出轮询实际有效的时间。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

别理我 2024-08-25 18:49:09

只要不出问题,就会出现 200 OK。因此,只要 HTTP 请求成功,您就应该始终获得该状态。不需要做任何特别的事情。

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.

乖乖公主 2024-08-25 18:49:09

从 PHP 5.4.0 开始,您可以使用 http_response_code()

<?php http_response_code(200); ?>

As of PHP 5.4.0 you can use http_response_code():

<?php http_response_code(200); ?>
戏剧牡丹亭 2024-08-25 18:49:09

要完成 hitautodestruc post,使用 PHP <5.4,您也可以设置

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

..但是以任何方式发送 200 代码都是无用的,因为在请求完成时默认情况下已经发送了它,并且如果服务器端没有发生错误(5xx)

也许您正在寻找这样的东西?

HTTP/1.1 206    Partial Content

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文