2

at my whits end with this...

The problem I have is that around the same time (roughly 60-70 mins through the request) the success function is called for the ajax request, but the tomcat logs prove that the request is still running.

(perspective: the request is supposed to either return an empty string ("") or a html page (of errors) however when the success function is called, it returns a string of length 2 result = " " (2 white space characters)

I cannot get this to reproduce in chrome, only IE (which is a problem as we cater specificity for IE)

At first I though it was a jQuery issue as I have multiple polls running when the request is sent (to update jQuery progress bar info)

However...

When I test this with just one asynchronous ajax request (not jQuery) that calls a Java method that just loops for 3 hours printing out in the log each second, it always calls success around the 3600 second mark (still another 7200 seconds remaining).

Example code:

var http_request = false;
  if (window.XMLHttpRequest) {
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/text');
    }
  }
  else if (window.ActiveXObject) {
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch (e) {}
    }
  }
  if (!http_request) {
    alert('Giving up: Cannot create an XMLHTTP instance');
    return false;
  }
  url += "&random=" + Math.random();
  http_request.open('GET', url, true);
  http_request.onprogress = function () { };
  http_request.ontimeout = function () { };
  http_request.onerror = function () { }; 
  http_request.onreadystatechange = function(){
    if (http_request.readyState == 4) {
      if (http_request.status == 200) {
        result = http_request.responseText;
        alert("success: ("+result.length+") ["+result+"]");             
      }
    }   
  }; 

NOTE: this is not a time-out error (at least not an ajax one) as the ajax time-out options seem to work correctly and return time-out errors accordingly, but as I have said, its not a time-out error...the success function is called too early.

Hope somebody can help :)

Cheers,
Steve.

Update:

I've run the request with the network tab capturing and it shows that the result was aborted: here

Thanks @ArunPJohny, this has given me a new direction to look in. Is there some kind of "onAbort" ajax callback? As I would have thought this kind of response would be caught by the "error:" callback

Update 2:

I have since found my way to a number of SO topics, more notably: xmlhttprequest timeout / abort not working as expected?

Tim provides some useful links for catching the abort, but still no clue as to why its getting aborted.

follow-on: here

Community
  • 1
  • 1
Steve
  • 178
  • 2
  • 12
  • What has been returned by the server? Is the content correct or somehow broken? – MaxArt Mar 25 '13 at 10:27
  • if you are using jquery why struggle with `XMLHttpRequest` – Arun P Johny Mar 25 '13 at 10:46
  • Hi all thanks for input...Using XMLHttpRequest to prove the error IS NOT with jQuery. Exactly the same happens using the solution suggested by @ArunPJohny. regardless of timeout settings, cashing etc...if the request takes around an hour or more it always returns " " (2 white space characters) so my alert is "success: (2) [ ]" – Steve Mar 25 '13 at 11:54
  • In reply to @MaxArt im not sure if the 2 whitespace thing is normal, as often in ajax requests i have to create a test variable and strip out all whitespace characters (testResult = result.replace(/\s/g, '');) if I'm expecting an empty string (non empty strings are formatted html pages (errors returned for an error dialog)). The correct result SHOULD be an empty string (when the request eventually does finish) – Steve Mar 25 '13 at 11:58
  • can you monitor the request using the network tab of your browser to see whether it is still in progress when the request callback is called – Arun P Johny Mar 25 '13 at 12:00
  • Did not know about that tab...nice to know for the future. I'll have a look tonight (can't run the tests while I'm working) and get back to you tomorrow. Thanks for help so far. – Steve Mar 25 '13 at 15:19
  • In order to debug what happens on the server, I'd suggest to create an object implementing `ServletRequestListener` and observing when it runs `requestDestroyed`. – MaxArt Mar 25 '13 at 16:01

0 Answers0