Jquery 在POST请求后读取ETag的AJAX
我想知道,对于通过ajax发出的客户端POST请求,如何读取附加到服务器响应的ETag。目前,我在客户端发布这样的帖子,并从服务器获得了实际的响应主体:Jquery 在POST请求后读取ETag的AJAX,jquery,ajax,rest,Jquery,Ajax,Rest,我想知道,对于通过ajax发出的客户端POST请求,如何读取附加到服务器响应的ETag。目前,我在客户端发布这样的帖子,并从服务器获得了实际的响应主体: $.ajax({ type: "POST", accepts: "text/plain", url: "http://localhost:3000/somewhere", data: JSON.stringify(someObject), contentType:
$.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"});
提前感谢您抽出时间。看一看
基本上,success函数中的第三个参数是XHR请求:
...
success: function (data, textStatus, xhr) {
console.log(xhr.getResponseHeader('ETag'));
}
...
contentType:“application/json;charset=UTF-8”和dataType:“text”,什么?我正在发送一个json,希望得到纯文本(string)的响应。太棒了!非常感谢你。正如我所料,这很容易!祝你有美好的一天!只要我被允许,我就会接受。嘿,很高兴我能帮上忙!