request.xhr在Ext JS中未定义

Vol*_*nov 6 ajax xmlhttprequest readystate extjs4.1

我的网站是使用Ext JS 4.1框架和ASP .Net MVC v3制作的.呈现新帧时,有19个单独的AJAX请求用于以JSON格式检索数据.所有请求都是Ext.Ajax.request()所熟悉的.例:

Ext.Ajax.request({
    url: getOrderLink,
    method: "GET",
    params: { recId: orderRecId },
    headers: {
        'Accept': 'application/json'
    },
    success: function (response) {
        var order = Ext.decode(response.responseText);
        ...
    }
});
Run Code Online (Sandbox Code Playgroud)

在某些情况下,ext-all.js中存在错误

onStateChange : function(request) {
    if (request.xhr.readyState == 4) {
        this.clearTimeout(request);
        this.onComplete(request);
        this.cleanup(request);
    }
},
Run Code Online (Sandbox Code Playgroud)

请求没有属性xhr,以便request.xhr.readyState抛出异常"无法读取未定义的属性'readState'".此错误不会出现在所有请求中,也不会影响站点工作(成功检索响应).有时这些错误根本不会出现.默认情况下,所有请求的超时设置为30秒,每个请求大约需要1.5-2秒.我正在使用谷歌浏览器21.你能不能告诉我为什么会这样.

old*_*ard 2

当且仅当您有断点或“调试器”时,问题似乎才会发生;与 AJAX 相关的任何内容。对我来说,它发生在 Chrome 中,还没有尝试过其他浏览器。

就我而言,当我在商店的加载事件处理程序中设置断点(如下面的代码示例)时,就会发生这种情况。

但是,如果您也在框架本身的 Ext onStateChange 函数内设置断点,则会发生错误。

如果禁用断点和debugger;调用可以消除错误,您可以安全地忽略它!

ExtJS 论坛上有一个类似的帖子。Sencha 可能会添加修复程序。

Ext.define('MyApp.controller.MyController', {
    extend: 'Ext.app.Controller',

    stores: ['Projects'],

    init: function () {
        this.getProjectsStore().addListener(
            "load",
            this.onProjectsStoreLoaded,
            this
        );
    },

    onProjectsStoreLoaded: function () {
        console.log('MyController: onProjectsStoreLoaded');

        debugger; // <- this causes the errors to appear in the console

        SomeOtherThingsIWantedToDebug();
    }
}
Run Code Online (Sandbox Code Playgroud)