By using jquery ajax function, I can do something like:
$.ajax({
url: url,
type: 'GET',
async: true,
dataType: 'json',
data: data,
success: function(data) {
//Handle server response here
},
error: function(xhr, status, error){
//Handle failure here
}
});
I got two questions to ask based on above code:
When will the jquery.ajax() error
callback be called??
What if server response to me a json object with string message "There is an error". Which means the request is still send successfully, but I got server response {message: "There is an error"}
.
I think no matter what string value server is responsed, if client got server's response, the jquery.ajax() success
callback will be triggered anyway.
I'd like to ask if server specifically returns to me a JSON object with string value like {message: 'There is an error'}
, could server do something so that this response could be handled in jquery.ajax() error
callback instead of success
callback?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…