There is a submit button that serializes some forms and submits them correspondingly to different handlers on the server. When the data have been sent, I would like to redirect to another page where the user can see an overview of the results. How can I do it so? Redirecting right away does not work since the page does not have enough time to submit the data (or it looks so).
The following fails:
$(document).ready(function(){
$('#submit_all_button').submit(function(){
var querystring = $('#q1').serialize();
$.get('/change_q1', querystring);
var querystring = $('#q2').serialize();
$.get('/change_q2', querystring);
var querystring = $('#q3').serialize();
$.get('/change_q3', querystring);
window.location.href = "/main";
return false;
});
});
The same problem arises when the submit action is to redirect to /main page.
Use the
success functionof jQuery get() and keep track whether all your updates are send. So the last success function call finally redirects your page.