jQuery - get AJAX response headers

前端 未结 2 671
萌比男神i
萌比男神i 2020-11-29 11:11

How do we get access to the response headers when we fire an ajax request using jQuery? I tried with the below code as per the suggestions given in some sites. But xhr

2条回答
  •  旧巷少年郎
    2020-11-29 11:37

    For backward compatibility with XMLHttpRequest, a jqXHR object will expose the following properties and methods: getAllResponseHeaders() and getResponseHeader(). From the $.ajax() doc : http://api.jquery.com/jQuery.ajax/

    For jQuery > 1.3

    success: function(res, status, xhr) { 
      alert(xhr.getResponseHeader("myHeader"));
    }
    

提交回复
热议问题