怎样在外部读取到jquery ajax中回调函数的值



 $.ajax({    
        url:'/mall/credit',
        type: 'get',
        dataType:'json',
        success: function(response){
            credit = response.data.credit;
        },

        error: function(){
            alert("error");
        }

    });

jquery Ajax JavaScript

蓝大人浏览器 9 years, 5 months ago

 function test(callback){
    $.ajax({    
        url:'/mall/credit',
        type: 'get',
        dataType:'json',
        success: function(response){
            credit = response.data.credit;
            callback(credit);
        },
        error: function(){
            alert("error");
        }
    });
}
test(function(data){
    console.log(data);
})

一裤一裤... answered 9 years, 5 months ago

可以在外面定义一个变量,然后在回调里赋值

淡定帝就是我 answered 9 years, 5 months ago

Your Answer