extjs4全局网络异常监听器 [英] extjs4 global network exception listener

查看:150
本文介绍了extjs4全局网络异常监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个listener,它将侦听所有网络请求错误,如下所示:

I want to write a listener that will listen to all network requests errors, something like this :

Ext.Ajax.on('requestexception', function(conn, response, options) {
    if (response.status === 555) {
        Ext.Msg.alert('test', 'test');
    }
});

上面的代码仅适用于通过Ext.Ajax.request()进行的请求,如何重写它,以便它也可以用于表单提交,找不到URL错误等.

The above code works only for requests via Ext.Ajax.request(), how to rewrite it so it could work also for form submits, url not found error etc.

在服务器端,我有Spring MVC调度所有请求,如果有error,则返回555的响应状态.

On server side I have Spring MVC that dispatches all requests and if there is any error, the response status of 555 is returned.

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);
     }
 });

推荐答案

这应该有效:

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 ); 
    }
});

看看精确的handleResponse()方法的源代码,我从上面复制了大部分代码.

Have a look at the source code for the exact handleResponse() method from which I copied most of the code above.

这篇关于extjs4全局网络异常监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆