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

AJAX重定向和跨域 #4

Open
WeiShengv99 opened this issue Nov 20, 2021 · 0 comments
Open

AJAX重定向和跨域 #4

WeiShengv99 opened this issue Nov 20, 2021 · 0 comments

Comments

@WeiShengv99
Copy link
Owner

HTTP 203 重定向发生的跨域问题

具体场景是一个Ajax请求在 203 的情况下, Header上有location字段,这代表该接口被打重定向到这个地址,这个时候浏览器会有一些默认的操作:

  1. ajax 是一个为了局部更新页面而产生的一个 api ,所以当一个ajax 在 203 的时候,并不会默认去跳转到 location 页面,因为这是一个局部的更新。
  2. 浏览器在收到203后,会去确认是否有location字段,如果有这个字段,那么会再去请求这个地址,也是一个http请求,但是之前203的ajax 的回调并不会立马运行,而会等待新建的请求结束,再去判断是否success或则error
  3. 当新的请求失败的时候,回去运行error 回调,成功则跳转。

然而问题是部分业务下location的页面会发生跨域的问题。

后来通过把ajax 请求切换为form 提交的方式去试用浏览器默认的跳转行为,来避开跨域的问题。

@WeiShengv99 WeiShengv99 changed the title 网络重定向 AJAX重定向和跨域 Nov 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant