Ajax返回确定,但在其他函数调用时变得不确定

时间:2018-10-08 10:05:50

标签: javascript

我有两个js函数'select'和'currentselect',select将调用currentselect来获取返回值。我不知道为什么select()在currentselect()返回OK时变得未定义?

function select () {
    $.ajax({
        type:'POST',
        url:some url,
        data: {id:$(this).data},
        error: function(info){
            alert("There was a problem, please contact administrator");
        },
        success: function(info){
            var sel = currentselect(info.pmc);
            console.log(sel); // getting undefine //???
        }
    });
}

function currentselect(target) {
    $.ajax({
        type: "GET",
        url: url,
        data:{target:target},
        error: function(data){
            $("#ms"+target).append("No data was found! Please contact page owner.");
        },
        success: function(data){
console.log(data); // return OK as follow [{…}]0:{id: "7", country: "Italy", …} length:1 //
            return data;
        }
    });
}

0 个答案:

没有答案