我有3个js文件:
app.js
$.ajaxSetup({
error : function(request) {
switch (request.status) {
...
case 422:
App.handle422(request);
break;
...
}
}
});
race-registration.js
var RaceRegistrationProxy = {
url : App.getContextPath() + "/api/event",
submitRegistration : function(raceId, eventId, data) {
return $.ajax({
type : "POST",
url : this.url + "/" + eventId + "/" + raceId + "/registration",
data : JSON.stringify(data),
contentType : "application/json",
beforeSend : function(request) {
App.setHeader(request)
}
});
}
}
main.js
...
$("form").submit(function(event) {
event.preventDefault();
$("[id$='-message']").hide();
var data = {
'team_name' : $("#teamName").val(),
'category_id' : $("#categoryId").val(),
'members_ids' : memberIds
};
RaceRegistrationProxy.submitRegistration(raceId, eventId, data)
.done(registrationOk)
.fail(registrationFail);
});
...
在此特定方法中发生错误时,如何禁用ajaxSetup?我已经尝试过在commitRegistration方法中使用global:false。
最佳答案
我将错误属性添加到Submit Registration方法中的ajax调用中。
submitRegistration : function(raceId, eventId, data) {
return $.ajax({
type : "POST",
url : this.url + "/" + eventId + "/" + raceId + "/registration",
data : JSON.stringify(data),
contentType : "application/json",
beforeSend : function(request) {
App.setHeader(request)
},
error : function(){}
});
}
关于javascript - 禁用ajaxSetup,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34953276/