0

我需要使用 ExtJS 3.4.0 库在 Javascript 函数中分配响应值以返回它,该函数自然终止而无需等待 ajax 响应,因此 count 的值始终为零,我需要知道我是否可以这样做或者如果有替代方案。

谢谢

function test() {
    var count = 0;
    Ext.Ajax.request({
        url: "/Controller/Action",
        method: "POST",
        success: function(response) {
            count = Ext.decode(response.responseText);
        }
    });

    if (count > 1) {
        return false;
    }

    return true;
}
4

1 回答 1

0

您需要在成功函数中添加 return 语句:

function test() {
    var count = 0;
    Ext.Ajax.request({
        url: "/Controller/Action",
        method: "POST",
        success: function(response) {
            count = Ext.decode(response.responseText);
            if (count > 1) {
               this.other(false);
            }
            this.other(true);
        },
        scope: this
    }); 
},

function other(param){
     console.log(param);
  }
于 2013-10-26T05:32:40.027 回答