Reputation: 20150
In the code below, I'm handling for status code 200 and 401. What do I do if I want to direct control to a function that handles all codes apart from 200 and 401?
$.ajax({
type: "POST",
dataType: "json",
data:POSTData,
url: 'http://localhost/api/user/authenticate',
statusCode: {
200: function() {
alert("ok");
},
401: function() {
alert("Invalid Credentials");
}
}
});
Upvotes: 8
Views: 1283
Reputation: 2912
try something like this:
$.ajax({
type: "POST",
dataType: "json",
data:POSTData,
url: 'http://localhost/api/user/authenticate',
complete: function(xhr, statusText){
switch(xhr.status){
case 200:
alert("ok");
case 401:
alert("invalid credentials");
....
etc
}
}
});
Upvotes: 3