www.webdeveloper.com
Results 1 to 2 of 2

Thread: and Javascript query continus loop not working with ajax and js

  1. #1
    Join Date
    May 2006
    Posts
    412

    and Javascript query continus loop not working with ajax and js

    Hi all,

    I have a problem i am trying to develop a continuious setimeout loops so after 5 minutes it refreshes the page again of which is ment to be for an application i am building

    now this is my Javascript code and what i am wanting is to refresh the page every 5 minutes or 15 minutes and do that for infiinite time without having to fresh the current page so it keeps going non-stop.

    so this is what i have atm

    HTML Code:
    <script src="ajaxreload.js" type="text/javascript">
    var i=1;
    function doAlert()
    {
    	doccument.write("<body onLoad=\"loadurl('time.php')\" id=\"output\"></body>");
    if(i<3){setTimeout('doAlert()',2000)}
    }
    onload=function(){
    doAlert()
    }
    </script>
    theres a function for my ajax if you want to take a look at it

    HTML Code:
    function loadurl(dest) { 
     
    try { 
            // Moz supports XMLHttpRequest. IE uses ActiveX. 
            // browser detction is bad. object detection works for any browser 
            xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP"); 
    } catch (e) { 
            // browser doesn't support ajax. handle however you want 
    } 
     
    // the xmlhttp object triggers an event everytime the status changes 
    // triggered() function handles the events 
    xmlhttp.onreadystatechange = triggered; 
     
    // open takes in the HTTP method and url. 
    xmlhttp.open("GET", dest); 
     
    // send the request. if this is a POST request we would have 
    // sent post variables: send("name=aleem&gender=male) 
    // Moz is fine with just send(); but 
    // IE expects a value here, hence we do send(null); 
    xmlhttp.send(null); 
    } 
     
    function triggered() { 
    // if the readyState code is 4 (Completed) 
    // and http status is 200 (OK) we go ahead and get the responseText 
    // other readyState codes: 
    // 0=Uninitialised 1=Loading 2=Loaded 3=Interactive 
    if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
    { 
            // xmlhttp.responseText object contains the response. 
            document.getElementById("output").innerHTML = xmlhttp.responseText; 
    } 
    } 
    Now what i am wanting to do is get time.php to be freshed each time after 5 minutes has pass then after another 5 minutes repeats the same process is this possible if so how would i get this done and fix this issue?

    Thanks,William

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by william232 View Post
    HTML Code:
    <script src="ajaxreload.js" type="text/javascript">
    var i=1;
    function doAlert()
    {
    	doccument.write("<body onLoad=\"loadurl('time.php')\" id=\"output\"></body>");
    if(i<3){setTimeout('doAlert()',2000)}
    }
    onload=function(){
    doAlert()
    }
    </script>
    document.write() will rewrite the document, that means will change the session. If so, your var i will be always 1.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles