Mathieu
Mathieu

Reputation: 5695

How to redirect after a successful DELETE request

I have an HTML form performing a DELETE request (method = POST & hidden X-HTTP-Method-Override = DELETE)

When the DELETE request is successful, how do I tell the browser to redirect to another page? Is 303 + header location okay?

Currently, the browser doesn't display the empty response but keep the previous response (I guess because of the 204 status code). If I add a location header (still 204 status code) it does not change the location.

With 303+location I have the desired behavior but I wonder if 303 is a valid status code after a successful DELETE. What about 202 (Accepted) DELETE ?

Upvotes: 5

Views: 5285

Answers (1)

fumanchu
fumanchu

Reputation: 14559

303 plus Location is the best choice. Don't worry about what a "successful DELETE" is or means, because you're using POST, which has a different set of semantics, and 303 is tailor-made for redirecting POST requests:

10.3.4 303 See Other

The response to the request can be found under a different URI and SHOULD be retrieved using a GET method on that resource. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource. The new URI is not a substitute reference for the originally requested resource. The 303 response MUST NOT be cached, but the response to the second (redirected) request might be cacheable.

Upvotes: 2

Related Questions