FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Ajax Stack Overflow IE

 


cr3ativ3
Ok, I spent hours trying to find a way to reload a ajax request without an event happening and I could surprisingly not find any examples with a google search, I once remember seeing something like a wait 5 seconds then request again but I can't find it anymore.

Anyways, after giving up and I started doing other stuff I got the idea to have it redo the ajax request once the last request was complete (at stage 4) of course it worked perfectly in FireFox so I am like yaaaa!, then I decided to test it in IE but all I get is a stack overflow here is a image of the exact message:



Here is the code for my document all it basically is, is a live clock:

Code:

<html>
<head>
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
   var ajaxRequest;  // The variable that makes Ajax possible!
   
   try{
      // Opera 8.0+, Firefox, Safari
      ajaxRequest = new XMLHttpRequest();
   } catch (e){
      // Internet Explorer Browsers
      try{
         ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
         try{
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (e){
            // Something went wrong
            alert("Your browser broke!");
            return false;
         }
      }
   }
   // Create a function that will receive data sent from the server
   ajaxRequest.onreadystatechange = function(){
      if(ajaxRequest.readyState == 4){
         document.myForm.time.value = ajaxRequest.responseText;
         ajaxFunction();
      }
   }
   ajaxRequest.open("GET", "serverTime.php", true);
   ajaxRequest.send(null);
}

//-->
</script>
</head>
<body onLoad="ajaxFunction();">

<form name='myForm'>
Name: <input type='text' name='username' /> <br />
Time: <input type='text' name='time' />
</form>
</body>
</html>


Anyways ya I was wondering if someone could point out how I could make it work in IE I have an idea but not sure if it will work? Maybe like pause the for 1 second at stage 4 so that it doesn't redo the request so quickly:

Code:

   // Create a function that will receive data sent from the server
   ajaxRequest.onreadystatechange = function(){
      if(ajaxRequest.readyState == 4){
         document.myForm.time.value = ajaxRequest.responseText;
                       ::Some Pause Text Here::
         ajaxFunction();
      }
   }


Thanks for reading this and I hope someone can help!
jabapyth
a stack overflow is what happens when your computer runs out of stack(the place where your computer manages function calls). This can be caused by an iterative loop that doesnt break out, or, in this case, by recursing to much.
To wait five seconds and then request again, do this:
Code:
function ajaxFunction(){
      // ... put ajax code here ...
      // and end with:
     setTimeout(ajaxFunction, 5000) // call again in 5000 milliseconds
}


Good Luck
cr3ativ3
Thank you so much! I owe you.
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.