gpt4 book ai didi

javascript - 如何通过 HTTP 返回 "noop"文档

转载 作者:行者123 更新时间:2023-11-29 17:30:40 27 4
gpt4 key购买 nike

我有一个可以做很多事情的 CGI 脚本。我试图使脚本非常简单和可移植。我只需要某种方式让用户在不丢失当前页面的情况下向服务器发送消息。到目前为止,我有以下过程:

  1. 用户从 CGI 脚本加载“状态页面”。
  2. 状态页面有一个 javascript 计时器,每两秒从服务器读取一次数据(不是整个页面)并相应地更改状态页面。
  3. 用户单击超链接元素以在服务器上启 Action 业。
  4. CGI 从点击接收参数并启 Action 业。
  5. CGI 发送响应 \n

此时 Firefox 询问用户是否要下载 CGI 脚本,当然该脚本只是 CGI 发送的 \n。相反,我希望浏览器完全忽略响应。如果我的 CGI 脚本没有回显 \n,apache 会报错。我该怎么做才能告诉浏览器忽略响应并留在当前页面上?请注意,我不想重新加载当前页面。我认为对于这种情况必须有某种“noop”HTTP 响应。

最佳答案

发回带有 204 HTTP 状态代码的响应。来自 RFC 2616 aka Hypertext Transfer Protocol -- HTTP/1.1 :

10.2.5 204 No Content

The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. The response MAY include new or updated metainformation in the form of entity-headers, which if present SHOULD be associated with the requested variant.

If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view.

The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.

关于javascript - 如何通过 HTTP 返回 "noop"文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4505120/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com