Stack overflow Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PriyeshSax
    New Member
    • Jun 2009
    • 5

    Stack overflow Error

    This is recursive function , once result displayed on browser i am calling tht function again for updation

    Code:
    function retrieveURL(url) 
    {
    if (window.ActiveXObject) { // Working on IE 
    req = new ActiveXObject("Microsoft.XMLHTTP");
    if (req) { 
    req.onreadystatechange = processStateChange;
    req.open("GET", url, true); 
    req.send();
    }
    }
    }
    function processStateChange() {
    if (req.readyState == 4) { 
    var characters = document.getElementById("characters"); 
    var result = req.responseText; 
    if(result.length > 50)
    {
    characters.value=result;
    result=null;
    req=null;
    } 
    retrieveURL('CPUutil.do'); 
    }
    }
    I am unable to understand why i am getting stack overflow exception, sometimes it'll work good , is this is because of cache problem ,, ?
    while debugging with alert boxes .i'll came to know that if i'll put multiple alert boxes it will work fine,
    Last edited by Dormilich; Jun 17 '09, 10:48 AM. Reason: Please use [code] tags when posting code
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    For recursion to work, you need a base point (to end the recursion) which you don't have, so the stack will obviously overflow.

    Comment

    • PriyeshSax
      New Member
      • Jun 2009
      • 5

      #3
      Thanks a lot for your reply,
      But I want this page to be continuously refresh with updated results. I want to resubmit same request again n again but it is not going on specified url .

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Then why not use setInterval() to make regular requests?

        Comment

        • PriyeshSax
          New Member
          • Jun 2009
          • 5

          #5
          Response time form server is not definite.. though it is synchronized on server side ,i don wan to increase thread waiting pool .only way to make request is when response arrives

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Either make an Ajax object which deals with all requests, or use Comet/reverse Ajax where the data is "pushed" from the server.

            Comment

            • PriyeshSax
              New Member
              • Jun 2009
              • 5

              #7
              actully this is my first Ajax based page n i don know how to create AjaxObject which deals with all requests....cou ld u please tell me (in short)how to create ajax object or how to implement Comet Ajax..i'll be vry thnkful 2 u ...

              Comment

              • PriyeshSax
                New Member
                • Jun 2009
                • 5

                #8
                Now this code is working fine without throwing "stack overflow" exception on my local machine, but after deploying it on IBM web sphere server it is throwing same exception (Stack Overflow)

                Code:
                var xmlhttp;
                function retrieveURL(url) 
                {
                xmlhttp=null;
                if (window.XMLHttpRequest)
                  {// code for Firefox, Mozilla, IE7, etc.
                  xmlhttp=new XMLHttpRequest();
                  }
                else if (window.ActiveXObject)
                  {// code for IE6, IE5
                  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                  }
                if (xmlhttp!=null)
                  {
                  xmlhttp.onreadystatechange = processStateChange;
                  xmlhttp.open("GET",url,true);
                  xmlhttp.send(null);
                  }
                else
                  {
                  alert("Your browser does not support Ajax Objects.");
                  }
                }
                
                
                function processStateChange() {
                
                if (xmlhttp.readyState==4)
                  {// 4 = "loaded"
                  if (xmlhttp.status==200)
                    { // Complete		
                			 var characters = document.getElementById("characters");			
                			 var result = xmlhttp.responseText;					 
                			 if(result.length > 50)
                			 {		
                			 characters.value=result;
                			 result=null;			
                			}
                		retrieveURL('CPUutil.do');						
                		 }
                  }
                }

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Here's one simple example. There are quite a few more if you search. It should give you an idea. You can then try a new request every second. If the first one is still in progress, it will not make a new request. Once it's complete, it will make the new request.

                  Comment

                  Working...