有一个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/