SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    auto submit form using ajax every 5 minutes without reloading page

    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???

  2. #2
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,615
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    This is based on some code I wrote a while back for a heartbeat function:

    Code JavaScript:
        var seconds = 300;    
        var isPulse=true;
     
        function heartbeat(){
            if(isPulse){
                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
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    Non-Member Max Height's Avatar
    Join Date
    Dec 2011
    Posts
    303
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    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.

  4. #4
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    in ajax


    myForm.submit();


    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

    myForm.submit();
    reloads the page...

    how i can solve this??

  5. #5
    Non-Member Max Height's Avatar
    Join Date
    Dec 2011
    Posts
    303
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •