同步完成AJAX

时间:2013-02-12 20:03:25

标签: jquery ajax

我在另一个AJAX调用中有一个AJAX调用。

我正在使用$.ajax方法:

$.ajax({
    type: 'POST',
    url: '/xx/xxx',
    success: function (data) {
        if(data == true){
            var j = MethodThatCallAjaxFunction();
            //some code here
        }
    }    
});

在评论j之后执行代码之前,如何确保填充//some code here的值?

1 个答案:

答案 0 :(得分:3)

你做不到。 MethodeThatCallAjaxFunction可以是同步(坏),也可以附加回调。

function mtcaf() {
    return $.ajax();
}
//snip
if (data == true) {
    mtcaf().done(function () {
        //some codes here
    });
}