javascript - How to get response headers from iron-form Polymer -
i have form, submit so:
form.addeventlistener("iron-form-response", function(event) { //how can access response headers here? }); form.submit(); i know way can access response body:
event.detail.response but want server response headers. need it, because response may contain in headers tokens, must store in cookies.
the event.detail <iron-request>, exposes underlying xmlhttprequest via e.detail.xhr, allows use getresponseheader(name) specific header:
_onresponse(e) { const header = e.detail.xhr.getresponseheader('x-special-header'); ... } example:
<dom-module id="x-foo"> <template> <iron-form on-iron-form-response="_onresponse"> <form method="post" action="//httpbin.org/post"> <label for="myname">my name</label> <input type="text" id="myname" name="name"> <button>submit</button> </form> </iron-form> </template> <script> class xfoo extends polymer.element { static is() { return 'x-foo'; } _onresponse(e) { console.debug('response header("content-type")', e.detail.xhr.getresponseheader('content-type')); console.debug('all response headers', e.detail.xhr.getallresponseheaders()) } } customelements.define(xfoo.is, xfoo); </script> </dom-module>
Comments
Post a Comment