I am trying to filter somehow the request response based on the returned status code. I found how I can get the status code using the "complete" statement, but I do not know how to get the handler to the data. In the example I want to include the error statement and the success statement in the complete handler, and being able there to process the data.
$.ajax({
dataType: 'json',
url: url,
cache: false,
type: 'GET',
async: true,
error: function(){
//process error
},
success: function(data){
//process data
},
complete: function(transport) {
switch(transport.status){
开发者_高级运维 case 200:
//process data
break;
case 202:
//process data
break;
case 304:
//do not process data
break;
default:
//default processing
break;
}
}
}
});
You actual response is transport
So you can use transport.responseText
to get the string response (before it's parsed, that happens in success
)
精彩评论