我想知道,如何读取通过ajax发生的客户端POST请求附加到服务器响应的ETag。目前,我正在从客户端这样发布消息,并且从服务器获取了响应的实际内容:
$.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
});
服务器通过设置以下标头来响应POST请求:
res.writeHead (200, {"ETag": "\"" + anETag + "\"", "Content-Type": "text/plain"});
在此先感谢您的时间。
最佳答案
看看Get response header jquery ajax post Set-Cookie
基本上,成功函数中的第三个参数是XHR请求:
...
success: function (data, textStatus, xhr) {
console.log(xhr.getResponseHeader('ETag'));
}
...
关于jquery - AJAX在POST请求后读取ETag,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19606138/