Search code examples
javascriptajaxpolymerpolymer-1.0

With iron-ajax, how to read the headers of a response?


When a response for a request arrives, is there any way to read the response headers?


Solution

  • The response event handlers gets passed the <iron-request> as the second argument. <iron-request> has an xhr property that is the XMLHttpRequest used to make the request. You should be able to get the response headers from that.

    <iron-ajax on-response="ajaxResponse"></iron-ajax>
    ...
    ajaxResponse: function(e, request) {
      var headers = request.xhr.getAllResponseHeaders();
    }