XMLHttpRequest abort() and subsequent error in call to onreadystatechange

P

Peter Michaux

Hi,

I am trying out the Ajax timeout example in Flanagan's book p492. It
works fine in Opera but in Firefox the the call to request.abort()
doesn't stop onreadystatechange being called. I found some references
to this problem in the group archives and on google but no solutions I
can seem to implement here. The troublesome code is below. I added what
I think are fixes for the IE memory leak probem in two places (which
doesn't change this problem) and the third argument to open().

After the timeout function runs I see

[Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult:
"0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::
http://localhost:3000/flanaganTimeout.html :: anonymous :: line 68"
data: no]

Where line 68 is the line "if (request.status == 200) {". How can I
stop onreadystatechange from being called?

HTTP.get = function(url, callback, options) {
var request = HTTP.newRequest();

var timer;
if (options.timeout) {
timer = setTimeout(function() {
request.abort();
if (options.timeoutHandler) {
options.timeoutHandler(url);
}
request = null; // IE leak
},
options.timeout);
}

request.onreadystatechange = function() {
if (request.readyState == 4) {
if (timer) {clearTimeout(timer);}
if (request.status == 200) {
callback();
}
request = null; // IE leak
}
}
request.open("GET", url, true); // added third argument
request.send(null);
return;
};


Thank you,
Peter
 
A

ASM

Peter Michaux a écrit :
Hi,

I am trying out the Ajax timeout example in Flanagan's book p492. It
works fine in Opera but in Firefox the the call to request.abort()
doesn't stop onreadystatechange being called. I found some references
to this problem in the group archives and on google but no solutions I
can seem to implement here. The troublesome code is below. I added what
I think are fixes for the IE memory leak probem in two places (which
doesn't change this problem) and the third argument to open().

After the timeout function runs I see

[Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult:
"0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::
http://localhost:3000/flanaganTimeout.html :: anonymous :: line 68"
data: no]

what did you give as argument 'callback' when calling HTTP.get() ?
 
P

Peter Michaux

ASM said:
Peter Michaux a écrit :
Hi,

I am trying out the Ajax timeout example in Flanagan's book p492. It
works fine in Opera but in Firefox the the call to request.abort()
doesn't stop onreadystatechange being called. I found some references
to this problem in the group archives and on google but no solutions I
can seem to implement here. The troublesome code is below. I added what
I think are fixes for the IE memory leak probem in two places (which
doesn't change this problem) and the third argument to open().

After the timeout function runs I see

[Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult:
"0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::
http://localhost:3000/flanaganTimeout.html :: anonymous :: line 68"
data: no]

what did you give as argument 'callback' when calling HTTP.get() ?

Here is the full call.

HTTP.get('/ajax/sleep_long',
function(){console.log('server responded');},
{timeout:2000,
timeoutHandler:function(){console.log('timeout');}}
);

I'm using firebug in Firefox with this test so console.log() works much
like alert() but without stalling everything. I tried with alert() for
Opera and Firefox. Works in Opera but doesn't work in Firefox.

Thank you,
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top