I would like to see whether the header was text/html or text/xml. If it was text/html then there was an error and I would rather catch that before proceeding.
The getResponseHeader() method returns the value as a UTF byte sequence. Note: The search for the header name is case-insensitive. If you need to get the raw string of all of the headers, use the getAllResponseHeaders() method, which returns the entire raw header string.
setRequestHeader() The XMLHttpRequest method setRequestHeader() sets the value of an HTTP request header. When using setRequestHeader() , you must call it after calling open() , but before calling send() . If this method is called several times with the same header, the values are merged into one single request header.
While you can't ready any headers of HTML response in JS, you can read Server-Timing header, and you can pass arbitrary key-value data through it.
To get HTTP headers with Node. js, we can use the res. headers properties. const http = require("http"); const options = { method: "HEAD", host: "example.com", port: 80, path: "/", }; const req = http.
Use the getResponseHeader() method.
Minimal example:
<script> function hand () { console.log(this.getResponseHeader('content-type')); } var x = new XMLHttpRequest(); x.onreadystatechange = hand; x.open('GET', 'index.html', true); x.send(); </script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With