lundi 26 janvier 2015

Else Statement in statusCode check for Ajax

I am trying to react to the http status codes in some ajax. I am successful in reacting to specified status codes. But I do not want to have to check for every single code. Is there a way to write an else statement in the following code? Or does ajax not do that?



<script>
$(function () {
var url = "google.com";
$.ajax(url,
{
statusCode: {
200: function () {
//react to status code 200
},
404: function () {
//react to status code 404
},
503: function () {
//react to status code 503
}
//if neither 200, 404, or 503, then react some way
}
});
});
</script>


I have tried writing else{ using ,, using nothing, etc. No success. And I don't think the generic switch statement will work with what I am trying to do.


Aucun commentaire:

Enregistrer un commentaire