views:

153

answers:

5

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

+1  A: 

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.

MattJ
+11  A: 

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.

Eddie
New trick thanks.
JoshBerke
Thank you, this is what I was looking for.
Mekk
And this is why there are no stupid questions.
jms
+1  A: 

Suppose you do that.

What does the user do? Submit the form again, of course.

Several times.

Then they decide your site is broken, and leave.

MarkusQ
Still in some error scenarios this is what I find useful...
Mekk
I'm curious. Why would you want to give no feedback whatsoever? Wouldn't it be better to just hide / grey out the submit button in such cases? What's the advantage of hiding the process from the user, unless you're up to no good...hmmm.
MarkusQ
A: 

No. The HTTP protocol consists of a request-response cycle. The server can't decide NOT to reply (It can, but then it's breaking the protocol and commiting an error).

troelskn
However, there is a defined HTTP response code that tells the browser to *not* update or change what it is currently displaying.
Eddie
A: 

I think that you need javscript to do that, you can send the request and depending on server response the javascript can do a return false, avoiding the refresh/reload of the actual page.

I dont know about the 204 response, but maybe that way you can do it from the server side.

Another way of doing it (also javascript) is to make a return false, right after the request is send, and depending on server response (with ajax) you can modify the actual page or send the user to another page.

SinneR