Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

ajax - Why does my CORS API request fail in Chrome?

I'm doing a cross-domain GET request from a 3rd party API that requires authentication. It works fine on Safari on OSX, but so far nowhere else (Chrome, Safari iOS, ..). In Chrome I get a 401 error (and the "A cookie associated with a cross site resource ... was set without the SameSite attribute" warnings).

My request:

$.ajax({
  url: "https://example.com/api",
  type: "GET",
  dataType: "json",
  crossDomain: true,
  xhrFields: {
       withCredentials: true
  },

  success: successCallback,
  error: errorCallback
});

My intent is to have this request sent from my client site, and it will be able to do API calls so long as the user has recently logged on to the 3rd party site and session cookies are preseent.

I've seen discussion about Chrome recently increasing the requirement for CORS to have certain cookie settings for SameSite. It's not clear to me if this is my problem, and if so, are there any workarounds?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...