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] 28.Ajax 和 Fetch 区别 #89

Open
qiilee opened this issue Sep 29, 2019 · 0 comments
Open

[ajax] 28.Ajax 和 Fetch 区别 #89

qiilee opened this issue Sep 29, 2019 · 0 comments
Labels

Comments

@qiilee
Copy link
Member

qiilee commented Sep 29, 2019

答案:

  • ajax 是使用 XMLHttpRequest 对象发起的,但是用起来很麻烦,所以 ES6 新规范就有了 fetch,fetch 发一个请求不用像 ajax 那样写一大堆代码。
  • 使用 fetch 无法取消一个请求,这是因为 fetch 基于 Promise,而 Promise 无法做到这一点。
  • 在默认情况下,fetch 不会接受或者发送 cookies
  • fetch 没有办法原生监测请求的进度,而 XMLHttpRequest 可以
  • fetch 只对网络请求报错,对 400,500 都当做成功的请求,需要封装去处理
  • fetch 由于是 ES6 规范,兼容性上比不上 XMLHttpRequest
@qiilee qiilee added the Ajax label Sep 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant