Hi, Does anyone know why Prototype invokes the Ajax.Responders onComplete method on IE and FireFox but not on Safari when Ajax.Request is aborted by invoking the transport.abort() method? (Is it a bug for Safari not implementing the XMLHttpRequest object correctly?) If I invoke the transport.abort(), it screws up the Ajax.activeRequestCount on Safari since Ajax.Responders onComplete is not invoked. Please let me know if there is a work around for this or if there is a better way of aborting Ajax request.
on 2008-06-19 10:48
on 2008-06-19 11:43
This happens because onTimeout never fires on Safari which updates the
activeRequestCount.
Instead of invoking abort on transport directly you can extend the
Ajax.Request class with the following method. It takes care of calling
onTimeout for Safari thus updating the activeRequestCount.
Ajax.Request.prototype.abortRequest = function() {
this.aborted = true;
this.transport.abort();
if(/Konqueror|Safari|KHTML/.test(navigator.userAgent)){
(this.options['onTimeout'] || Prototype.emptyFunction)();
}
}
Just paste the code anywhere after your prototype.js include.
Usage:
var myReq = new Ajax.Request(blah..blah..);
myReq.abortRequest();
on 2008-06-19 12:00
Thanks for the tip. I tried it right away, but it didn't work (do I
have to implement onTimeout callback to decrement
Ajax.activeRequestCount?)
I did the following and it seems working fine.
...
...
...
this._request.transport.abort();
// for Opera and Safari
if(Prototype.Browser.Opera || Prototype.Browser.WebKit)
{
Ajax.activeRequestCount--;
}
On Jun 19, 6:43 pm, "Irfan, Ghouseuddin Syed" <is...@corp.untd.com>
on 2008-06-19 12:17
Yes that should work.
You can even try the following:
Ajax.Request.prototype.abortRequest = function() {
this.transport.abort();
if(/Konqueror|Safari|KHTML/.test(navigator.userAgent)){
Ajax.activeRequestCount--;
}
}
or
Ajax.Request.prototype.abortRequest = function() {
this.transport.abort();
if(Prototype.Browser.Opera || Prototype.Browser.WebKit){
Ajax.activeRequestCount--;
}
}