【问题标题】:Can i use the error functionality of jquery ajax call to a ext js ajax call?我可以将 jquery ajax 调用的错误功能用于 ext js ajax 调用吗?
【发布时间】:2016-12-16 08:50:23
【问题描述】:

在我的应用程序中有两种类型的 ajax 调用。

1.Ext js ajax 调用。 2.jquery ajax调用。

以下是它们各自的两个代码示例。

1.Ext js ajax 调用。

Ext.get(document.body).mask('Processing...', 'x-mask-loading');
    searchURL = getFormAction('hm.web.HMCaregiverManager', 'getCountryKeyTx');
    var conn = new Ext.data.Connection();
    conn.request({
        url: searchURL,
        method: 'POST',
        params: {"hm_caregiver_country_uno"  : countryUno
                },
        success: function(responseObject) {

            var countryKeyTx  = responseObject.responseText;
            initCountryDropDowns(countryKeyTx);

            Ext.get(document.body).unmask(true);

        },
         failure: function() {
             Ext.Msg.alert('Failure', 'Unable to contact server');
             Ext.get(document.body).unmask(true);
         }
    });

2.Jquery ajax 调用。

$.ajax({
                type: 'POST',
                url: validateAjaxURL,
                success: function (data) {                  
                    var returnData = data;  
                    if (returnData.match("^selectedUno-")) {    

                          $('#new_caregiver_popup_div').dialog('close');    
                    }else{
                        $("#new_caregiver_popup_div").html(data);
                    }
                },
                error: function (jQXHR, textStatus, errorThrown) {
                    handleAjaxError(jQXHR, textStatus, errorThrown);                        
                }
        });

我在 jquery ajax call error: 选项中使用“jQXHR、textStatus、errorThrown”参数以获取有关错误的详细信息。我也想获取 ext js ajax 调用失败的错误详细信息。那么我可以包含那个错误函数而不是 ext js ajax 调用的失败函数。那么代码会是这样的。

Ext.get(document.body).mask('Processing...', 'x-mask-loading');
    searchURL = getFormAction('hm.web.HMCaregiverManager', 'getCountryKeyTx');
    var conn = new Ext.data.Connection();
    conn.request({
        url: searchURL,
        method: 'POST',
        params: {"hm_caregiver_country_uno"  : countryUno
                },
        success: function(responseObject) {

            var countryKeyTx  = responseObject.responseText;
            initCountryDropDowns(countryKeyTx);

            Ext.get(document.body).unmask(true);

        },
         **failure: function (jQXHR, textStatus, errorThrown) {
                    handleAjaxError(jQXHR, textStatus, errorThrown);                        
                }**
    });

这个 ext js ajax 代码可以工作吗?任何帮助将不胜感激。

【问题讨论】:

  • 嗯,你试过了吗?它奏效了吗? docs 声明成功和失败都有 2 个参数。
  • 不,我没有尝试过。如何使用这些失败参数获取失败详细信息?
  • Umm.. 在浏览器控制台中查看它们有哪些属性?我不明白你为什么不试试看。

标签: jquery ajax extjs


【解决方案1】:

在 extjs 中,所有请求都是 ajax。负责这个的类是 Ext.Ajax

这里是 API: https://docs.sencha.com/extjs/5.1.3/Ext.Ajax.html#method-request

Ext.Ajax.request({
    url: 'ajax_demo/sample.json',
    success: function(response, opts) {
        var obj = Ext.decode(response.responseText);
        console.dir(obj);
    },
    failure: function(response, opts) {
        console.log('server-side failure with status code ' + response.status);
    }
});

故障函数有两个参数:

failure :  Function
    The function to be called upon failure of the request. The callback is passed the following parameters:

    response :  Object
        The XMLHttpRequest object containing the response data.
    options :  Object
        The parameter to the request call.

【讨论】:

  • 非常感谢您的回复。如果出现 ajax 错误(内部服务器错误、解析器错误、找不到文件等),我可以识别那些使用响应、选择参数的错误吗?
  • 当然。所有属性都在这里描述:link
猜你喜欢
  • 1970-01-01
  • 2014-11-22
  • 1970-01-01
  • 2014-10-24
  • 1970-01-01
  • 2011-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多