【发布时间】:2016-05-23 20:36:10
【问题描述】:
我正在尝试使用 jquery buy 执行 CORS 请求,但出现了奇怪的行为。当我使用 curl 执行请求时,一切正常。但是当我使用 jQuery 时,事情就大错特错了。在我的浏览器的“网络”选项卡中,我可以检查来自后端的请求和响应,一切都正确 但虽然我有 Access-Control-Expose-Headers: Set-Cookie header 当我尝试使用 console.log(response.getResponseHeader("Set-Cookie"));当我尝试使用 console.log(response.getAllResponseHeaders()) 在控制台中打印出我的 ajax 请求的响应标头时,我只得到这 3 个标头:
Pragma: no-cache
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Expires: 0
我用来执行请求的代码是:
$.ajax({
method: "POST",
url: "http://localhost:8808/storage/login",
data: {
username: email,
password: password,
},
success: function(data, textStatus, response){
console.log(response.getAllResponseHeaders());
console.log(response.getResponseHeader("Set-Cookie"));
this.setState({showAlert: true, alertMessage: "You are logged in.", alertType: "success"});
}.bind(this),
error: function (xhr, status, err) {
this.setState({showAlert: true, alertMessage: "Wrong email or password", alertType: "danger"});
}.bind(this)
});
【问题讨论】:
标签: jquery ajax reactjs header response