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

Ajax Stack Overflow IE

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:


<script language="javascript" type="text/javascript">
//Browser Support Code
function ajaxFunction(){
   var ajaxRequest;  // The variable that makes Ajax possible!
      // Opera 8.0+, Firefox, Safari
      ajaxRequest = new XMLHttpRequest();
   } catch (e){
      // Internet Explorer Browsers
         ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
            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;
   }"GET", "serverTime.php", true);

<body onLoad="ajaxFunction();">

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

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:


   // 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::

Thanks for reading this and I hope someone can help!
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:
function ajaxFunction(){
      // ... put ajax code here ...
      // and end with:
     setTimeout(ajaxFunction, 5000) // call again in 5000 milliseconds

Good Luck
Thank you so much! I owe you.
I saw a post about this problem in another forum. Where a guy mentioned that the callback is not running async. I would just like to add to the post above that it is not actually the time delaying which is fixing the problem here. It is the fact that the setTimeout function runs async effectively clearing the stack. So the time is not important at all.

Thats to say if you set it at 1 millisecond like I did to fix the same issue you will find it will not continue to grow the stack regardless of how fast your computer is and how quick you make the timeout. Hope this clears up whats happening for anyone else having confusion over this.


Fire Boar
Note that the more time you give, the more responsive your user's web experience will be (depending on the application). Forcing the user to make lots of requests is bad for both you and your user, but if you need an ajax function to call regularly, make sure:
- The data sent client to server is minimal.
- The data sent server to client is minimal.
- The time between requests is enough for your application to do what it needs to.

- An email program with an auto save draft feature (like Google Mail) only needs to make an AJAX request every 30 seconds or so to keep a draft saved.
- An online browser-based non-Flash multiplayer game needs to make an AJAX request far more often, maybe once every second or less.
Related topics
(official) IE 7 Topic
AJAX tutorial
Co myslicie o mojej stronce??
Killing LILO on my laptop
IE CSS problems
AJAX, PHP, XHTML some critism pls!
most secure O.S
Firefox vs IE ?
Ajax - Qu'en pensez-vous ?
Slow Javascript in IE
IE problems.. PLEASE HELP!!
What can recursive function do?
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

© 2005-2011 Frihost, forums powered by phpBB.