jQuery withCredentials无法在Safari中运行?

我正在尝试使用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));
    }
});

有任何想法吗?是否有特定的东西我需要服务器端为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

是否有丢失的CORS标头,仅限Safari需要?

解决方法

我很遗憾地说,但对于这个问题,没有一个非常优雅的解决方案.
Apple最近采用了严格的政策来防止第三方cookie – link

This means users only have long-term persistent cookies and website data from the sites they actually interact with and tracking data is removed proactively as they browse the web.

我能想到的最佳解决方案是将用户重定向到第三方域中托管的登录页面,然后在登录后返回原始页面.这样就可以存储cookie(因为用户直接与其域进行了交互),并且您还可以将其作为来自原始域的第三方cookie进行交互.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...