Is there a way to expire a form after the user presses submit and redirected to another external url.
I want to restrain the user from clicking the browser's back button and resubmit the form.
I have tried to set NoCache and NoStore in the Controller but the browser still held in cache (Chrome).
This has nothing to do with MVC, the cache, or your browser; this is how HTTP headers handle POST requests.
Normally, when submitting a form to an internal or external URL you can avoid POST data being resubmitted by issuing a 302 "Moved Temporarily" redirect after you've processed the data, or by sending the request with AJAX or cURL.
There are multiple examples with answers on Stack Overflow, simply search for "prevent form resubmission"
Related
I have a form on a web page. When I click the Submit button, the browser sends the form data within a POST request. If I refresh the result then it sends the data again.
I want to see what the POST data was without re-sending the form. How can I do it?
I know, there is the Developer Tools dialog which can show me what requests are being sent to the server. But, in order to analyze a request, I need to turn the DT on before I send the request. So, if I want to see what the POST content was, I need to send the form again, which I wanted to avoid.
I am sure that the browser knows what content of the POST was because if I refresh the result page, it will send the same POST data again. How can I access this information?
I would like to know the answer how to do it in Firefox but I am interested in Chrome as well.
Sometimes, a user session expires, no matter the reason. The user is redirected to the login page, as my routes sends the user there in case of Auth::guest().
Then it sends them back after successful login to an ajax/json page (like a list of images in json) - this happens because I'm using the Redirect::intended() call. This is completely unusable then - how do people work around this?
Using Redirect::guest() saves the requested URL to the session key url.intended. If you use Redirect::guest() in a filter on an AJAX route, this will still be the case and the URL of that AJAX call will be where the user is sent.
You can use if(Request::ajax()) {} to do something different for AJAX responses, like returning an error JSON instead of a redirect.
I am sending ajax request to spring controller from dialog box. The request is processed correctly, but after that dialog box is get closed and page is redirected to the url send in request.
I tried #RequestStatus(HttpStatus.OK) to not send any view name. Still page gets refreshed.
What I want is to remain dialog box open which sends request and page should not get refreshed.
How does browser send back cookie to the server during post requests. How is this different than the form data that is sent during a post ?
Also are the values of cookies for a particular domain automatically sent back to the domain for all its subsequent requests ?
Thanks,
Murtaza
There is no different between how cookies are sent for GET and POST requests.
Form data is data such as fields from an HTML Form, eg. name, username, file, etc...
Any cookies sent back in a response from a domain will be sent back to the server in subsequent requests. This is true in web browsers at least, if you are doing this in code, you might have to write additional code to handle cookies.
This should work for AJAX calls made by your browser as well as full pages. Every request, be it full pages, images or AJAX calls will have the Cookies attached if they are going to an appropriate domain and path.
These primers on cookies and HTTP POST would be useful:
http://en.wikipedia.org/wiki/HTTP_cookie
http://en.wikipedia.org/wiki/POST_(HTTP)
I just want to know what is the difference between sending parameter with ajax(post/get) to a servlet and sending them with "submit" .
Thanks for your help.
A standard form submit sends a new HTTP request (POST or GET) and loads the new page in the browser. In Ajax, the data is sent to the server (POST or GET) in the background, without affecting the page at all, and the response is then received by javascript in the background, again without affecting the page at all.
(The javascript can, of course, then use the data received from the server to update some of the page content.)
Ajax is generally useful where only a small section of the page content will change.
At the simplest, with ajax, you don't witness page refresh while submitting form data. And if you don't use it eg you use submit buttons, you witness page refresh. Both submit the data.
Server side handling of both are exactly the same. The server is not concerned about how the post request is made.
The difference is in how the browser (client side) responds to both the actions. The browser usually decides to make a request for an entire page if it is a form submit; otherwise, it just updates a part of the page.
From the servlet's point of view there is no difference. For the client, a submit will load a new page, while an Ajax request will parse the response with javascript code and act accordingly.
The form submit will reload the page that you are working on client side.,while in ajax call the call was made to server will not reload your client side page