469,319 Members | 2,390 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,319 developers. It's quick & easy.

Stack overflow Error

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

Expand|Select|Wrap|Line Numbers
  1. function retrieveURL(url) 
  2. {
  3. if (window.ActiveXObject) { // Working on IE 
  4. req = new ActiveXObject("Microsoft.XMLHTTP");
  5. if (req) { 
  6. req.onreadystatechange = processStateChange;
  7. req.open("GET", url, true); 
  8. req.send();
  9. }
  10. }
  11. }
  12. function processStateChange() {
  13. if (req.readyState == 4) { 
  14. var characters = document.getElementById("characters"); 
  15. var result = req.responseText; 
  16. if(result.length > 50)
  17. {
  18. characters.value=result;
  19. result=null;
  20. req=null;
  21. retrieveURL('CPUutil.do'); 
  22. }
  23. }
  24.  
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,
Jun 17 '09 #1
8 2709
acoder
16,027 Expert Mod 8TB
For recursion to work, you need a base point (to end the recursion) which you don't have, so the stack will obviously overflow.
Jun 17 '09 #2
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 .
Jun 17 '09 #3
acoder
16,027 Expert Mod 8TB
Then why not use setInterval() to make regular requests?
Jun 17 '09 #4
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
Jun 17 '09 #5
acoder
16,027 Expert Mod 8TB
Either make an Ajax object which deals with all requests, or use Comet/reverse Ajax where the data is "pushed" from the server.
Jun 17 '09 #6
actully this is my first Ajax based page n i don know how to create AjaxObject which deals with all requests....could u please tell me (in short)how to create ajax object or how to implement Comet Ajax..i'll be vry thnkful 2 u ...
Jun 18 '09 #7
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)

Expand|Select|Wrap|Line Numbers
  1. var xmlhttp;
  2. function retrieveURL(url) 
  3. {
  4. xmlhttp=null;
  5. if (window.XMLHttpRequest)
  6.   {// code for Firefox, Mozilla, IE7, etc.
  7.   xmlhttp=new XMLHttpRequest();
  8.   }
  9. else if (window.ActiveXObject)
  10.   {// code for IE6, IE5
  11.   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  12.   }
  13. if (xmlhttp!=null)
  14.   {
  15.   xmlhttp.onreadystatechange = processStateChange;
  16.   xmlhttp.open("GET",url,true);
  17.   xmlhttp.send(null);
  18.   }
  19. else
  20.   {
  21.   alert("Your browser does not support Ajax Objects.");
  22.   }
  23. }
  24.  
  25.  
  26. function processStateChange() {
  27.  
  28. if (xmlhttp.readyState==4)
  29.   {// 4 = "loaded"
  30.   if (xmlhttp.status==200)
  31.     { // Complete        
  32.              var characters = document.getElementById("characters");            
  33.              var result = xmlhttp.responseText;                     
  34.              if(result.length > 50)
  35.              {        
  36.              characters.value=result;
  37.              result=null;            
  38.             }
  39.         retrieveURL('CPUutil.do');                        
  40.          }
  41.   }
  42. }
Jun 18 '09 #8
acoder
16,027 Expert Mod 8TB
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.
Jun 18 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by ip4ram | last post: by
7 posts views Thread by Aguilar, James | last post: by
5 posts views Thread by jbix | last post: by
6 posts views Thread by Daz | last post: by
3 posts views Thread by capes | last post: by
12 posts views Thread by Geoff Cox | last post: by
5 posts views Thread by moondaddy | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.