469,286 Members | 2,442 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

XMLHttpRequest abort() and subsequent error in call to onreadystatechange

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

Oct 28 '06 #1
2 6894
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() ?

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();
Oct 28 '06 #2

ASM wrote:
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

Oct 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Henri Sivonen | last post: by
6 posts views Thread by Nathan | last post: by
5 posts views Thread by Peter Michaux | last post: by
1 post views Thread by geevaa | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.