Skip to content

Commit

Permalink
docs: update issue 237
Browse files Browse the repository at this point in the history
  • Loading branch information
toFrankie committed Mar 22, 2024
1 parent 89d515d commit 647635f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions archives/2023/237.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: 解决跨域问题 Response to preflight request doesn't pass access control check
number: '#237'
link: 'https://github.com/toFrankie/blog/issues/237'
created_at: '2023-02-26 19:06:25'
updated_at: '2024-03-23 00:47:56'
labels:
- 前端
- Ajax
- '2021'
---
对于前后端分离,跨域问题老生常谈了,问题是这样的:

> Access to fetch at 'https://xxx/api/user' from origin 'http://h5.xxx.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values 'http://h5.xxx.com, *', but only one is allowed. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
翻译过来就是:

> 从源 `http://h5.xxx.com` 访问 `https://xxx/api/user` 处的访存已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:`Access-Control-Allow-Origin` 标头包含多个值 `http://h5.xxx.com, *`,但仅允许一个。 让服务器发送带有有效值的标头,或者,如果不透明的响应满足您的需要,请将请求的模式设置为 `no-cors`,以在禁用 CORS 的情况下获取资源。
原因是就是在服务器设置了允许跨域,同时又在 Nginx 代理又设置了一次。

只要移除其一即可解决。

0 comments on commit 647635f

Please sign in to comment.