我想知道,如何读取附加到通过 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
});
服务器通过设置如下 header 来响应 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 - POST 请求后 AJAX 读取 ETag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19606138/