7

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?

makerofthings7
  • 60,103
  • 53
  • 215
  • 448
  • possible duplicate of [Cross Domain Resource Sharing GET: 'refused to get unsafe header "etag"' from Response](http://stackoverflow.com/questions/5822985/cross-domain-resource-sharing-get-refused-to-get-unsafe-header-etag-from-re) – jamesmortensen Mar 11 '12 at 07:06
  • Through AJAX? Or just regularly loaded? – Waynn Lue Mar 11 '12 at 07:07
  • @Waynn - Both if possible.. I'm reading Jmort's link, though it's not totally clear to me – makerofthings7 Mar 11 '12 at 07:13
  • See [this answer](https://stackoverflow.com/a/12501696) for an answer to the second question (well, both really, could be a duplicate). – tne Dec 04 '14 at 17:32

1 Answers1

2

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.

Waynn Lue
  • 11,344
  • 8
  • 51
  • 76