Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

abort synchronous XMLHttpRequest

148 views
Skip to first unread message

kjh21

unread,
Apr 24, 2009, 1:30:04 AM4/24/09
to
I'm using FireFox 3.0.x and am having difficulty understanding the
behavior of the the abort( ) method when making a synchronous
XMLHttpRequest from JavaScript.

Using a call to window.setTimeout( ) just prior to the invoking the
send( ) method on my XMLHttpRequest object invokes a callback on a
function that allows me to check the readState of the request at the
specified timeout threshold. If the request is still in progress (as
indicated by the readyState of the corresponding XMLHttpRequest
object, I invoke the abort( ) method on the request.

My observation is that this completely kills the thread of control
associated with the original request. My expectation is that on abort
( ) the thread of control associated with the call to send( ) should
simply return or perhaps raise an exception.

Here's a representative sample of code

===========================================================

// using GoogleMaps factory for creating XMLHttpRequest object in a
browser independent way
var xmlhttp = new google.maps.XmlHttp.create( );

xmlhttp.open("GET", myURLGoesHere, false);

// Limit execution time of request time to 5 seconds
var timeoutID = window.setTimeout( function() { if (isCallInProgress
(xmlhttp) {xmlhttp.abort();}}, 5000 );

try {
xmlhttp.send( null );
}
catch ( e ) {
alert( "Caught Exception executing synchronous XMLHttpRequest: " +
e.message );
}
finally {
window.clearTimeout(timeoutID);
}

function isCallInProgress( xhr ) {
switch( xhr.readyState ) {
case 1:
case 2:
case 3: return true;
}
return false;
}
=====================================================

The timer and check for call-progress seem to work fine but if the
abort( ) method is invoked on my XMLHttpRequest object, the thread of
control on which the original send( ) method is executed seems to die
completely. It never returns from send( ) and no exception is raised.

Is this expected behavior?


andre...@gmail.com

unread,
May 14, 2009, 6:52:38 AM5/14/09
to

I have the same problem!!!!
but I think there's no solution for this behavior.. :-(

0 new messages