How can Javascript view the ETAG value of a HTTP response? Can ETAG be included in a request?

StackOverflow https://stackoverflow.com//questions/9653079

  •  11-12-2019
  •  | 
  •  

Question

Is it possible for javascript to read the ETAG value of a HTTP response?

Are there any issues in writing out an ETAG value in a HTTP Request to the server?

Was it helpful?

Solution

If it's a regularly loaded page, I think the HTTP request/response is already complete so Javascript can't access that information.

If it's an AJAX call, jQuery has the jqXHR object (documentation here), which says this.

The jQuery XMLHttpRequest (jqXHR) object returned by $.ajax() as of jQuery 1.5 is a superset of the browser's native XMLHttpRequest object. For example, it contains responseText and responseXML properties, as well as a getResponseHeader() method. When the transport mechanism is something other than XMLHttpRequest (for example, a script tag for a JSONP request) the jqXHR object simulates native XHR functionality where possible.

So you can call getResponseHeader() on the returned object in your success call to parse them out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top