【问题标题】:Ext.Ajax.isLoading return false when not all requests were completed未完成所有请求时,Ext.Ajax.isLoading 返回 false
【发布时间】:2013-11-15 09:55:16
【问题描述】:

在所有 Ajax 请求完成后,我需要在面板上执行一些操作,为此我添加了处理程序:

Ext.Ajax.on('requestcomplete', function(conn, response, options) {
    if (!Ext.Ajax.isLoading()) {
        // do action
    }
});

但我发现,如果通过Ext.Ajax.request方法Ext.Ajax.isLoading()执行请求时,无论该请求处于哪个状态,都会返回false

更新

Ext.Ajax.request({
    url: 'someUrl',
    timeout: 50000,
    scope: this,
    success: function(response, options) {
        //some action
    },
    params: {
        //some params
    },
    callback: function() {
        //some action            
    }
});

有人知道如何解决吗?或者可能存在其他方式来定义所有请求都已完成?

【问题讨论】:

  • 您的Ext.Ajax.request 和其他代码是什么样的?
  • @AntoJurkovic 这是简单的请求,没有什么不寻常的。添加示例。

标签: javascript ajax extjs extjs4.1


【解决方案1】:

不幸的是,isLoading() 函数只会告诉您请求是否仍在等待答复。所以false表示还没有开始或者已经结束了。

如果您知道要在面板中发送多少个请求,则可以使用本机 setInterval() 函数来解决问题。

它可能看起来像这样:

var itemsLoaded = 0, 
    loadFailed = false,
    pID;

for(var i = 0; i < amount; i++) {
  Ext.Ajax.request({
    url: 'someUrl',
    timeout: 50000,
    scope: this,
    success: function(response, options) {
        itemsLoaded++;
        //other actions
    },
    failure: function() {
        loadFailed = true;
    },
    params: {
        //some params
    },
    callback: function() {
        //some action            
    }
  });
}

pID = setInterVal(function() {
  if(itemsLoaded == amount) {
    clearInterval(pID);
    //place here the actions you want to do when all items are loaded
  } else if(loadFailed) {
    clearInterval(pID);
  }
}, 100); //milliseconds you want to retry the check

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-22
    • 1970-01-01
    • 1970-01-01
    • 2013-12-05
    相关资源
    最近更新 更多