PDA

View Full Version : the 'failure' event of 'Ext.util.JSONP.request' not work



losingrose
1 Nov 2011, 11:17 PM
When server response 404 error,the scripttag created by 'Ext.util.JSONP.request' will remain in header,and block other jsonp request.And the 'failure' event is not fired by 404 error.

The scripttag has a onerror event can catch this error.How can I overrite the jsonp request or extend it with a error handling?:s

losingrose
2 Nov 2011, 7:37 PM
I already overwrite the jsonp request in order to support the failure event.
It work properly now.:">

Ext.util.JSONP.request = function (o) {
o = o || {};
if (!o.url) {
return;
}

var me = this;
o.params = o.params || {};
if (o.callbackKey) {
o.params[o.callbackKey] = 'Ext.util.JSONP.callback';
}
var params = Ext.urlEncode(o.params);

var script = document.createElement('script');
script.type = 'text/javascript';
if (o.failure) {
script.onerror = function () {
document.getElementsByTagName('head')[0].removeChild(script);
Ext.util.JSONP.next();
o.failure();
}
};

this.queue.push({
url: o.url,
script: script,
callback: o.callback || function () { },
scope: o.scope || window,
failure: o.failure || function () { },
params: params || null
});

if (!this.current) {
this.next();
}
};