admin管理员组文章数量:1335176
I have a CGI script that does a lot things. I'm trying to keep the script very simple and portable. I just need some way for the user to send a message to the server without having to lose the current page. So far, I have the following process:
- User loads a "status page" from a CGI script.
- The status page has a javascript timer that will read data (not the entire page) from the server every two seconds and alter the status page accordingly.
- User clicks a hyperlink element to launch a job on the server.
- The CGI receives the parameters from the click and starts the job.
- The CGI sends a response of
\n
At this point Firefox asks the user if they want to download the CGI script and of course the script is just the \n
that the CGI sent. Instead, I want the browser to ignore the response altogether. If my CGI script does not echo a \n
apache gives an error. What could I do to tell the browser to ignore the response and stay on the current page? Note that I would rather not reload the current page. I'm thinking there must be some sort of "noop" HTTP response for such a case.
I have a CGI script that does a lot things. I'm trying to keep the script very simple and portable. I just need some way for the user to send a message to the server without having to lose the current page. So far, I have the following process:
- User loads a "status page" from a CGI script.
- The status page has a javascript timer that will read data (not the entire page) from the server every two seconds and alter the status page accordingly.
- User clicks a hyperlink element to launch a job on the server.
- The CGI receives the parameters from the click and starts the job.
- The CGI sends a response of
\n
At this point Firefox asks the user if they want to download the CGI script and of course the script is just the \n
that the CGI sent. Instead, I want the browser to ignore the response altogether. If my CGI script does not echo a \n
apache gives an error. What could I do to tell the browser to ignore the response and stay on the current page? Note that I would rather not reload the current page. I'm thinking there must be some sort of "noop" HTTP response for such a case.
- 3 @Noon: The term NOOP is just as valid. – cdhowie Commented Dec 22, 2010 at 0:10
- 1 How about a promise: NO½P – User1 Commented Dec 22, 2010 at 0:14
3 Answers
Reset to default 5Send back a response with the 204 HTTP status code. From 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.
Instead of trying to solve this problem on the server side, you might want to investigate a client side solution. For example, using jQuery you can easily initiate an AJAX asynchronous request to the server on a button click. You don't have to load a new page on the browser at all.
Instead of having the hyperlink be a real <a>
or <form>
with default behavior, have it be some clickable element whose clicks are handled by your client-side code. The Javascript code should send the job requests with XMLHttpRequest objects, putting it in plete control of how the response is handled.
本文标签: javascriptHow to return a quotnoopquot document over HTTPStack Overflow
版权声明:本文标题:javascript - How to return a "noop" document over HTTP - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742252927a2441097.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论