使用JQuery 1.8.2
我正在从一个AppServer(Front)到另一个AppServer(Back)服务器向一个应用程序发出CORS请求.当我从Front进行以下Ajax调用时,来自Back的302响应(安全检查)得到尊重,但我的JSESSIONID cookie未被存储:
$.ajax({
url : url,
dataType : 'html',
success : function(data, status, xhr) {
$(dataContainer).append(data);
},
complete: function(xhr, status, error) {
if (xhr.status != 200) {
$.logger(xhr.getResponseHeader('Location'));
}
}
});
Run Code Online (Sandbox Code Playgroud)
现在,如果我进行相同的调用,但添加了withCredentials,我的JSESSIONID正在被正确存储,但302重定向正在被删除.Chrome和Firefox(两者的最新版本)都停止处理请求.
$.ajax({
xhrFields: { withCredentials: true },
url : url,
dataType : 'html',
success : function(data, status, xhr) {
$(dataContainer).append(data);
},
complete: function(xhr, status, error) {
if (xhr.status != 200) {
$.logger(xhr.getResponseHeader('Location'));
}
}
});
Run Code Online (Sandbox Code Playgroud)
我试图从xhr对象获取重定向位置标题,但它是空的.
我在Back的所有回复中设置以下内容: …