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
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