Extjs, return Ajax return value

后端 未结 1 1806
甜味超标
甜味超标 2021-01-07 02:07

I have a problem with using Ajax.

function GetGrantAmazonItemCnt(){
    var cnt;
    Ext.Ajax.request({
        url : \'\',
        params : {},
        succ         


        
1条回答
  •  伪装坚强ぢ
    2021-01-07 02:36

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

    I would suggest refactoring your code to account for this.

    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);
            }
        });
    }
    

    0 讨论(0)
提交回复
热议问题