我想写一个listener来监听所有的网络请求错误,就像这样:
Ext.Ajax.on('requestexception', function(conn, response, options) {
if (response.status === 555) {
Ext.Msg.alert('test', 'test');
}
});上面的代码只适用于通过Ext.Ajax.request()的请求,如何重写它以使其也适用于表单提交,url未找到错误等。
在服务器端,我使用Spring MVC来分派所有请求,如果有任何error,则返回555的响应状态。
form.submit({
url: dispatcher.getUrl('savePlanRequest'),
//headers: {'Content-Type':'multipart/form-data; accept-charset=utf-8'},
scope: this,
method: 'GET',
params: {
scan: scan_id,
attachments: attachments_id,
parcels: parcels_id
},
success: function(form, action) {
this.fireEvent('plansaved', this);
Ext.Msg.alert(i18n.getMsg('success'), i18n.getMsg('gsip.view.plans.NewPlanForm.success_info'))
},
failure: function(form, action) {
console.log('failure');
//Ext.Msg.alert(i18n.getMsg('failure'), action.result.msg);
}
});发布于 2012-07-24 22:23:59
这应该是可行的:
Ext.override( Ext.form.action.Submit, {
handleResponse : function( response ) {
var form = this.form,
errorReader = form.errorReader,
rs, errors, i, len, records;
if (errorReader) {
rs = errorReader.read(response);
success = rs.success;
// Do something if success is false
}
this.callParent ( arguments );
}
});看看the source code中的handleResponse()方法,我从该方法复制了上面的大部分代码。
发布于 2013-01-16 00:01:37
我想你不需要重写任何东西。您可以将监听器放在Ext.Ajax单例上,如下所示:
Override Ext.data.Connection - Best Practice
另一种选择是使用Ext.util.Observable.observe()函数,如下所述:
http://www.sencha.com/forum/showthread.php?172269-Global-connection-handler-for-500-404-403-response-codes
Ext.util.Observable.observe(Ext.data.Connection);
Ext.data.Connection.on('requestexception', function(conn, response, options, eOpts) {
//...handle it
});https://stackoverflow.com/questions/11626428
复制相似问题