I have a series of forms that the user sees in sequence. When the user submits the form, it submits to a PHP file which will do some heavy work based on the submitted values, which might take 10 seconds or more to run, and I don’t want my users to have to wait before going to the next form.
Since I don’t really need to wait for the PHP to finish (I don’t need its results in order to proceed), is it possible to redirect the user to the next page on submit, and submit the form in the background so it doesn’t slow the user down?
I’ve heard that Javascript setTimeout() can mimic threading. Is this an option to make it run in parallel?
My JS function goNext() redirects the user to the next page (but does NOT submit). So would something like this work?
$('#submitButton').click(function() {
setTimeout(submitForm(), 1);
goNext();
});
function submitForm() {
$('#form').submit();
}
Every HTTP request will receive a response. So, in order to tell that your request worked, you would need to get a good response (200) from the server.
In order to do what you are suggesting, I think you should handle this on the server-side.