Owe*_*vey 8 safari ajax jquery xmlhttprequest cors
我正在尝试使用jQuery.ajax()withCredentials:真正的跨域但是由于某种原因它在Safari中不起作用.
它适用于Firefox,Chrome和IE(使用P3P标题)但在Safari中它不会进行身份验证.
我的代码非常简单:
$.ajax({
url: "http://www.someurl.com",
data: {},
contentType: "application/json",
type: "POST",
success: function(response) {
console.log(response);
},
crossDomain: true,
xhrFields: {
withCredentials: true
},
error: function(jqXHR, textStatus, errorThrown ) {
console.log(JSON.stringify(jqXHR));
}
});
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?是否有一些特定的东西需要服务器端让Safari接受cookie?
编辑:一旦我将"阻止cookie和其他网站数据"改为"永远不会",它就起作用了,但显然这不是面向公众网站的解决方案.
Safari不尊重服务器发送的cookie.这是我的标题(仅显示相关标题),请注意两个不同的域:
Request headers:
Referer: https://example.net
Origin: https://example.net
Host: example.org
Accept: application/json, text/javascript, */*; q=0.01
Response headers:
Content-Type: text/html; charset=utf-8
Access-Control-Allow-Credentials: true
Set-Cookie: authentication=8xIhPr9m0Fwky0qcE; expires=Fri, 09-Mar-2018 16:59:55 GMT; Max-Age=8640000; path=/; domain=example.org; secure; httponly
Access-Control-Allow-Origin: https://example.net
Run Code Online (Sandbox Code Playgroud)
是否有丢失的CORS标头,仅限Safari需要?