Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Responding so the browser does not do anything - is it possible?

Is it possible to make such a HTTP response, that the browser ignores it and keeps showing the previously displayed page?

I mean the following scenario:

a) user clicks something

b) some POST goes to the server (or GET, but let's stick with POST as more interesting)

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

d) server sends specifically crafted response

e) browser does not show the error page, does not show the empty page, does not redirect anywhere, does not reload - just keeps showing what it was showing as if the user never submitted the form

PS Of course it can be wrapped with AJAX, but I ask whether bare-bones non-javascript solution is possible

like image 399
Mekk Avatar asked Dec 17 '22 08:12

Mekk


2 Answers

Try returning HTTP 204 No Content. See the description of this response code in RFC 2616 (Hypertext Transfer Protocol -- HTTP/1.1 ) where it says:

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.

like image 56
Eddie Avatar answered Jan 02 '23 22:01

Eddie


This is a method usually called AJAX. It requires Javascript, and the XMLHttpRequest function.

Edit: Noticed your 'PS' at the bottom. The 204 response suggested in another answer looks like it might be a valid non-Javascript solution.

like image 22
MattJ Avatar answered Jan 02 '23 21:01

MattJ