Answering so, the browser does nothing - is this possible?

Is it possible to make such an HTTP response that the browser ignores it and continues to display the previously displayed page?

I mean the following scenario:

a) user clicks something

b) some POST is sent to the server (or GET, but let POST be inserted as more interesting)

c) the server decides that for some reason it does not want to send a response at this time

d) the server sends a specially crafted response

e) the browser does not show the error page, does not show the blank page, does not redirect anywhere, does not reload - it just continues to show that it showed as if the user had never submitted the form

PS Of course, it can be wrapped using AJAX, but I ask if a solution without javascript with bare bones is possible

+4
source share
5 answers

Try returning HTTP 204 without content. See the description of this response code in RFC 2616 (Hypertext Transfer Protocol - HTTP / 1.1) for a discussion of:

If the client is a user agent, he SHOULD NOT change the look of his document from this, which caused the request to be sent. This answer is primarily intended to introduce actions for actions that do not cause changes to the active agent of the user of the document, although any new or updated meta-information MUST be applied to the document in the active mode of the user agent.

+12
source

This is a method commonly called AJAX . This requires Javascript , and XMLHttpRequest .

Edit: Noticed your "PS" below. 204 the answer suggested in another answer looks as if it might be a valid solution other than Javascript.

+1
source

Suppose you do this.

What does the user do? Of course, submit the form.

Repeatedly.

Then they decide that your site is broken and leave.

+1
source

I think you need Javascript for this, you can send a request and depending on the server response, Javascript may return false, avoiding refreshing / reloading the actual page.

I do not know about the answer of 204, but perhaps this is how you can do this from the server side.

Another way to do this (also Javascript) is to make the return false immediately after sending the request, and depending on the server’s response (using ajax) you can change the actual page or send the user to another page.

0
source

No. The HTTP protocol consists of a request-response cycle. The server cannot decide NOT to respond (it can, but then it breaks the protocol and makes an error).

-2
source

All Articles