john_zakaria — 2012-01-03T06:05:15-05:00 — #1
he everyone please i want to know how to submit a form using ajax every 5 minutes without reloading page
i have a huge form for exams and i need to submit the form without the need to wait until pressing submit because the user may wait to think about the answer a very long time..
so i want to submit the form and at the same time i cant reload the page as it is in normal submit form..
so how i can submit form in the background without letting the user knows that the form is submitted???
force — 2012-01-03T20:33:03-05:00 — #2
This is based on some code I wrote a while back for a heartbeat function:
var seconds = 300;
var hb = setTimeout(heartbeat, seconds*1000);
//process stuff here
//isPulse can be whatever you want.
//It just needs to be something that will stop the recursive loop--an error condition, perhaps.
//Having a condition to stop this is a good idea, otherwise it will start acting like a memory leak.
//You could change the condition to be an amount of time, number of loops, or some other condition.
//function call is here
var hb = setTimeout(heartbeat, seconds*1000); //beat every 5 minutes
system — 2012-01-03T20:40:02-05:00 — #3
With a 5 minute interval, the previous ajax request should normally be finshed when the next one is sent, but you probably should first check if the previous request has actually completed before sending the next one.
john_zakaria — 2012-01-04T01:31:35-05:00 — #4
the exam time is 8 hours.. and the user may wait for a long time to think about an answer for a question..
i know that i can use ajax but my problem is that when i wrote
it reloads the page which is an error coz i dont want the user to wait until reloading the page and completing his exam.. at the same time the form may reload while he is typing any answer..
so i need to submit the form using ajax.. but
reloads the page...
how i can solve this??
system — 2012-01-04T02:20:03-05:00 — #5
You don't need to use .submit() in your ajax function to submit the data in the form.
Instead, you can send all the form data at any given time to a server side script with a POST transmission as opposed to a GET transmission. Sending the form data as a separate ajax post request will mean the page is not reloaded and the user will have no idea the form data has been sent to the server unless you actually change something in their browser when the ajax request has completed.
There are plenty of examples of sending data to the server as an ajax post here.