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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    460
    Thanks
    214
    Thanked 1 Time in 1 Post

    Resolved: clearInterval stops javascript from functioning.

    I have a script that works until I add the clearInterval command, and I am not sure what I have done wrong.

    The code is:
    Code:
    <script type="text/javascript">
    function loadChatTalkRefresh(File,ID,Msg){
    
    var xmlhttp; 
    
    if (window.XMLHttpRequest)  {
      xmlhttp=new XMLHttpRequest();
      }
    else {
    	try{
      xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }	
    }
    
    xmlhttp.onreadystatechange=function(){
      if (xmlhttp.readyState==4 && xmlhttp.status==200){
        document.getElementById(ID).innerHTML=xmlhttp.responseText;
    	empress = setInterval(function(){loadChatTalkRefresh(File,ID,Msg)},3000);
    	willow = clearInterval(empress,210000);
        }
      }
    
    var params=Msg;
    xmlhttp.open("POST",File,true);
    
    xmlhttp.setRequestHeader("Pragma", "Cache-Control:no-cache");
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", params.length);
    xmlhttp.setRequestHeader("Connection", "close");
    xmlhttp.send(params);
    }
    </script>
    Last edited by Jenny Dithe; 04-13-2011 at 04:45 AM.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,569
    Thanks
    23
    Thanked 643 Times in 642 Posts
    willow = clearInterval(empress,210000); Don't think you need a second parameter. clearInterval(empress); should do the trick.

  • Users who have thanked sunfighter for this post:

    Jenny Dithe (04-12-2011)

  • #3
    Regular Coder
    Join Date
    Sep 2010
    Posts
    460
    Thanks
    214
    Thanked 1 Time in 1 Post
    The second parameter was meant to be a time interval. I may have applied it incorrectly.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,238
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    Quote Originally Posted by Jenny Dithe View Post
    The second parameter was meant to be a time interval. I may have applied it incorrectly.
    As sunfighter says, there is no second parameter used in window.clearInterval().

  • Users who have thanked Philip M for this post:

    Jenny Dithe (04-12-2011)

  • #5
    Regular Coder
    Join Date
    Sep 2010
    Posts
    460
    Thanks
    214
    Thanked 1 Time in 1 Post
    OK so how would get the clearInterval to work 210000 msecs later.

    I tried a setTimeout:
    [CODE]
    var willow = setTimeout(clearInterval(empress),210000);
    [CODE]
    But it is a command not a function, so my web browser didn't like that.

  • #6
    Regular Coder
    Join Date
    Apr 2010
    Posts
    163
    Thanks
    3
    Thanked 25 Times in 25 Posts
    Make it a function.
    Code:
    var willow = setTimeout(function(){clearInterval(empress)},210000)
    take a point P, now call it Q.

  • Users who have thanked gizmo1650 for this post:

    Jenny Dithe (04-12-2011)

  • #7
    Regular Coder
    Join Date
    Sep 2010
    Posts
    460
    Thanks
    214
    Thanked 1 Time in 1 Post
    Worked perfectly. Thank you.


  •  

    Posting Permissions

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