Can I evaluate the response type of an $.ajax() call in success callback?

前端 未结 3 1769
生来不讨喜
生来不讨喜 2021-01-26 07:04

I am using jQuery to make an AJAX request to a remote endpoint. That endpoint will return a JSON object if there is a failure and that object will describe the failure. If the

3条回答
  •  渐次进展
    2021-01-26 07:40

    how about using the complete option?

    $.ajax({
       ...
    
       complete : function(xhr, status) {
       // status is either "success" or "error"
       // complete is fired after success or error functions
       // xhr is the xhr object itself
    
           var header = xhr.getResponseHeader('Content-Type');
       },
    
       ...
    });
    

提交回复
热议问题