ExtJS的,返回阿贾克斯返回值 [英] Extjs, return Ajax return value

查看:120
本文介绍了ExtJS的,返回阿贾克斯返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,使用Ajax。

I have a problem with using Ajax.

function GetGrantAmazonItemCnt(){
    var cnt;
    Ext.Ajax.request({
        url : '',
        params : {},
        success :function(response){
            cnt = response.responseText;
        }
    });
    return cnt; 
}

现在的问题是,之前获得Ajax响应,它返回CNT。 所以它总是返回NULL。

The problem is, before get the ajax response, it return cnt. so it always return NULL.

有没有办法做出正确的返回响应值?

is there a way to make right return response value?

谢谢你!

推荐答案

由于AJAX请求是异步的,要求回来,并成功处理程序调用之前你的CNT变量将返回。

Because the AJAX request is asynchronous, your cnt variable will return before the request comes back and the success handler is called.

我建议重构您的code考虑到这一点。

I would suggest refactoring your code to account for this.

这样做的一种方法是调用,从您的AJAX请求成功的处理程序,这种方式传递价值,它需要去叫GetGrantAmazonItemCnt()取功能:

One way to do this is to call whichever function that called GetGrantAmazonItemCnt() from the success handler of your AJAX request, this way passing the value to where it needs to go:

function GetGrantAmazonItemCnt(){
    var cnt;
    Ext.Ajax.request({
        url : '',
        params : {},
        success :function(response){
            cnt = response.responseText;
            FunctionThatCalledMe(cnt);
        }
    });
}

这篇关于ExtJS的,返回阿贾克斯返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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