function foo(arg, ajaxcomplete) {
$.ajax({
//ajaxcall...
success: function() {
//set ajaxcomplete to true
}
}
有什么方法可以做类似的事情来知道ajaxcall何时在函数中完成?谢谢
最佳答案
是的完成
。它在错误或成功回调后被触发。
function foo(arg, ajaxcomplete) {
$.ajax({
success: function() {
alert('O.K.');
},
complete: function(){
alert('We are done');
}
});
}
来自docs的描述:
complete(jqXHR, textStatus)Function, Array A function to be called when the request finishes (after success and error callbacks are executed). The function gets passed two arguments: The jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object and a string categorizing the status of the request ("success", "notmodified", "error", "timeout", "abort", or "parsererror"). As of jQuery 1.5, the complete setting can accept an array of functions. Each function will be called in turn. This is an Ajax Event.
关于JavaScript 输出函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9262912/