Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[js] 第349天 ajax请求中为何会出现OPTIONS请求? #2161

Open
haizhilin2013 opened this issue Mar 29, 2020 · 2 comments
Open

[js] 第349天 ajax请求中为何会出现OPTIONS请求? #2161

haizhilin2013 opened this issue Mar 29, 2020 · 2 comments
Labels
js JavaScript

Comments

@haizhilin2013
Copy link
Collaborator

第349天 ajax请求中为何会出现OPTIONS请求?

我也要出题

@haizhilin2013 haizhilin2013 added the js JavaScript label Mar 29, 2020
@Ari-ZH
Copy link

Ari-ZH commented Mar 31, 2020

https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Methods/OPTIONS
CORS会在请求前先发送OPTIONS请求

@bozaigao
Copy link

bozaigao commented Oct 10, 2020

这种方式被称为预检请求,所谓预检请求主要是因为浏览器的同源策略限制,浏览器限制跨请求一般有两种方式:1、浏览器限制跨域请求;2、跨域请求可以正常发起但是返回的结果被浏览器给屏蔽了;一般浏览器是根据第二种情况进行同源策略限制,但是虽然数据被浏览器屏蔽了跨域请求有可能已经对服务器数据库里面的数据产生了影响,为了规避这种情况,在这之前先进性一次预检请求,看服务器是否允许进行跨域请求,如果允许则携带数据进行真实请求。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
js JavaScript
Projects
None yet
Development

No branches or pull requests

3 participants