Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    460
    Thanks
    214
    Thanked 1 Time in 1 Post

    Cancel Previous Refresh request before new refresh

    Hi,

    I have the below code:
    Code:
    <script type="text/javascript">
    function loadQuickMessageCheck(File,ID){
    
    var xmlhttp; 
    
    if (window.XMLHttpRequest)  {
      xmlhttp=new XMLHttpRequest();
      }
    else {
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    
    xmlhttp.onreadystatechange=function(){
      if (xmlhttp.readyState==4 && xmlhttp.status==200){
        document.getElementById(ID).innerHTML=xmlhttp.responseText;
    	 eucalyptus = setInterval(function(){loadQuickMessageCheck(File,ID)},20000);
        }
      }
    
    xmlhttp.open("POST",File,true);
    xmlhttp.send();
    }
    </script>
    But I am overloading the server and crashing it. I've googled the issue and have found people with similar problems who talk about the need to cancel the last refresh request before they send the next refresh.

    I even found this nice piece of code which worked for someone else.

    try{window.clearTimeout(tRefresh)} catch(err) {}
    tRefresh = setInterval(setContext, varInterval*60*1000);
    }
    I am not sure if this is the solution that I am looking for but if it is all my attempts at applying this code has been a bit of a disaster.

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    974
    Thanks
    19
    Thanked 212 Times in 210 Posts
    I'm wondering if you know the difference between setInterval and setTimeout? I'm almost sure you would be wanting to use
    setTimeout .

  • Users who have thanked DaveyErwin for this post:

    Jenny Dithe (04-13-2011)

  • #3
    Regular Coder
    Join Date
    Sep 2010
    Posts
    460
    Thanks
    214
    Thanked 1 Time in 1 Post
    Thank you. I needed reminding about that


  •  

    Posting Permissions

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