是否有jQuery的AJAX调用任何模拟到“最后”? [英] Is there any analog to a 'finally' in jQuery AJAX calls?
本文介绍了是否有jQuery的AJAX调用任何模拟到“最后”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个Java终于模拟jQuery的AJAX调用?我有这个code在这里。在我的总是我抛出一个异常,但是我总是希望它去的则()方式。
call.xmlHtt preQ = $阿贾克斯({
网址:网址,
数据类型:JSON,
键入:GET
})永远(功能(processedDataOrXHRWrapper,textStatus,xhrWrapperOrErrorThrown){
扔东西;
})。然后(函数(){
警报(我想一直跑,不管是什么);
});
我曾尝试使用完成() 完整的(),然后在另一个总是(),但似乎没有任何工作。
解决方案
请参阅下面的例子:
$。阿贾克斯({
键入:GET,
数据类型:数据类型
的contentType:contentType中,
异步:TRUE,
网址:$('HTML表单:第n个孩子(1))ATTR('行动')+。? $('HTML表单:第n个孩子(1))序列化()。
成功:功能(数据){
的console.log(FUNFOU!);
},
错误:功能(数据){
的console.log(孬FUNFOU!);
},
完成:功能(数据){
的console.log(SEM pre FUNFA!);
//函数被调用时,请求结束
//(成功和错误回调被执行后)。
}
});
有关更详细的信息: http://api.jquery.com/jquery.ajax/
Is there a Java 'finally' analogue in jQuery AJAX calls? I have this code here. In my always I throw an exception, however I ALWAYS want it to go to the then() method.
call.xmlHttpReq = $.ajax({
url : url,
dataType : 'json',
type : 'GET'
}).always(function(processedDataOrXHRWrapper, textStatus, xhrWrapperOrErrorThrown) {
throw "something";
}).then(function() {
alert("i want to always run no matter what");
});
I have tried to use done(), complete(), and the another always(), but nothing seems to work.
解决方案
See this example:
$.ajax({
type: "GET",
dataType: dataType,
contentType: contentType,
async: TRUE,
url: $('html form:nth-child(1)').attr('action') + "?" $('html form:nth-child(1)').serialize(),
success: function(data) {
console.log("FUNFOU!");
},
error: function(data) {
console.log("NÃO FUNFOU!");
},
complete: function(data) {
console.log("SEMPRE FUNFA!");
//A function to be called when the request finishes
// (after success and error callbacks are executed).
}
});
For more informations: http://api.jquery.com/jquery.ajax/
这篇关于是否有jQuery的AJAX调用任何模拟到“最后”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文