2

I was wondering, how can I read an ETag that is attached to a server response for a client side POST request that has occured through ajax. At the moment I am POSTing like this from the client side and I get the actual body of the response from the server:

$.ajax({
        type: "POST",
        accepts: "text/plain",
        url: "http://localhost:3000/somewhere",
        data: JSON.stringify(someObject),
        contentType: "application/json; charset=UTF-8", 
        dataType: "text",
        success: function(data) {
            window.alert("Received back: '" + data + "'");
        },
        username: theUsername,
        password: thePassword
    });

The server responds to the POST request by setting the headers like this:

res.writeHead (200, {"ETag": "\"" + anETag + "\"", "Content-Type": "text/plain"});

Thanks in advance for your time.

MightyMouse
  • 13,208
  • 8
  • 33
  • 43

1 Answers1

2

Have a look at Get response header jquery ajax post Set-Cookie

Basically the third param in the success function is the XHR request:

...
success: function (data, textStatus, xhr) {
    console.log(xhr.getResponseHeader('ETag'));
}
...
Community
  • 1
  • 1
Darko
  • 38,310
  • 15
  • 80
  • 107
  • Great! Thank you very much. It was very easy as I expected! Have a great day! I will accept as soon as I am allowed. – MightyMouse Oct 26 '13 at 11:35