tags:

views:

139

answers:

5

I remember reading somewhere it's a good practice to redirect pages using GET to show the next page after a POST request. Why is it so?

+10  A: 

This way, if the user reloads the page, the browser won't send another POST.

For example, if the page is an order confirmation page, you don't want the order to be repeated if the user refreshes the page.

SLaks
A: 

I would assume this is so that the following page is bookmarkable.

lo_fye
Stack Overflow answers are not a good place to ass-u-me.
gahooa
I don't think my answer was bad - bookmarkability is a valid reason to use GET after a redirect. GET keeps the parameters in the querystring, which makes bookmarking dynamic pages possible. The accepted answer ("to avoid double posting") doesn't explain why to use GET, it just promotes not double posting.
lo_fye
A: 

It's because if a user submits a form and is taken to the thankyou page, then refreshes that page, the browser will prompt the user to resubmit the form, thus creating two posts to your data handler. If you redirect to the thankyou page with GET, the post vars are empty so the form won't be resubmitted.

I'm not sure it's still considered good practice - haven't heard anything on the subject for a while.

adam
A: 

GET is idempotent while POST isn't. If the user reloads the page (or returns there by clicking the browser's Back button), nothing breaks.

RegDwight
Well, it should work that way, at least. There's nothing requiring that on the web server side; `GET` can muck up anything the web site developer tells it to. Also, modern browsers prompt the user before reloading a `POST` page but not a `GET` page.
Mike D.
A: 

If you can't remember why it's good practice then maybe there isn't a good justification for it.

IMHO, it's a case of swings and roundabouts - and certainly easy to argue the converse - whether its good practice or not really depends on how it fits in with the rest of your code.

C.

symcbean
He's asking why it's good practice, so to answer him with a "You don't know, don't do it," isn't a great answer.
John