Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
fetch
提交
7232090c
F
fetch
项目概览
github
/
fetch
8 个月 前同步成功
通知
30
Star
25765
Fork
3216
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
fetch
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
7232090c
编写于
11月 13, 2019
作者:
D
David Graham
提交者:
GitHub
11月 13, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #734 from mislav/patch-1
Document more common pitfalls in the README
上级
37d10362
1364c857
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
20 addition
and
9 deletion
+20
-9
README.md
README.md
+20
-9
未找到文件。
README.md
浏览文件 @
7232090c
...
@@ -21,6 +21,7 @@ replacement for most uses of XMLHttpRequest in traditional web applications.
...
@@ -21,6 +21,7 @@ replacement for most uses of XMLHttpRequest in traditional web applications.
*
[
Handling HTTP error statuses
](
#handling-http-error-statuses
)
*
[
Handling HTTP error statuses
](
#handling-http-error-statuses
)
*
[
Sending cookies
](
#sending-cookies
)
*
[
Sending cookies
](
#sending-cookies
)
*
[
Receiving cookies
](
#receiving-cookies
)
*
[
Receiving cookies
](
#receiving-cookies
)
*
[
Redirect modes
](
#redirect-modes
)
*
[
Obtaining the Response URL
](
#obtaining-the-response-url
)
*
[
Obtaining the Response URL
](
#obtaining-the-response-url
)
*
[
Aborting requests
](
#aborting-requests
)
*
[
Aborting requests
](
#aborting-requests
)
*
[
Browser Support
](
#browser-support
)
*
[
Browser Support
](
#browser-support
)
...
@@ -188,6 +189,10 @@ fetch('/avatars', {
...
@@ -188,6 +189,10 @@ fetch('/avatars', {
cookies, always supply the
`credentials: 'same-origin'`
option instead of
cookies, always supply the
`credentials: 'same-origin'`
option instead of
relying on the default. See
[
Sending cookies
](
#sending-cookies
)
.
relying on the default. See
[
Sending cookies
](
#sending-cookies
)
.
*
Not all Fetch standard options are supported in this polyfill. For instance,
[
`redirect`
](
#redirect-modes
)
and
[
`cache`
](
https://github.github.io/fetch/#caveats
)
directives are ignored.
#### Handling HTTP error statuses
#### Handling HTTP error statuses
To have
`fetch`
Promise reject on HTTP error statuses, i.e. on any non-2xx
To have
`fetch`
Promise reject on HTTP error statuses, i.e. on any non-2xx
...
@@ -229,15 +234,6 @@ fetch('https://example.com:1234/users', {
...
@@ -229,15 +234,6 @@ fetch('https://example.com:1234/users', {
})
})
```
```
To disable sending or receiving cookies for requests to any domain, including
the current one, use the "omit" value:
```
javascript
fetch
(
'
/users
'
,
{
credentials
:
'
omit
'
})
```
The default value for
`credentials`
is "same-origin".
The default value for
`credentials`
is "same-origin".
The default for
`credentials`
wasn't always the same, though. The following
The default for
`credentials`
wasn't always the same, though. The following
...
@@ -258,6 +254,12 @@ fetch('/users', {
...
@@ -258,6 +254,12 @@ fetch('/users', {
})
})
```
```
Note: due to
[
limitations of
XMLHttpRequest
](
https://github.com/github/fetch/pull/56#issuecomment-68835992
)
,
using
`credentials: 'omit'`
is not respected for same domains in browsers where
this polyfill is active. Cookies will always be sent to same domains in older
browsers.
#### Receiving cookies
#### Receiving cookies
As with XMLHttpRequest, the
`Set-Cookie`
response header returned from the
As with XMLHttpRequest, the
`Set-Cookie`
response header returned from the
...
@@ -266,6 +268,15 @@ read with `response.headers.get()`. Instead, it's the browser's responsibility
...
@@ -266,6 +268,15 @@ read with `response.headers.get()`. Instead, it's the browser's responsibility
to handle new cookies being set (if applicable to the current URL). Unless they
to handle new cookies being set (if applicable to the current URL). Unless they
are HTTP-only, new cookies will be available through
`document.cookie`
.
are HTTP-only, new cookies will be available through
`document.cookie`
.
#### Redirect modes
The Fetch specification defines these values for
[
the `redirect`
option
](
https://fetch.spec.whatwg.org/#concept-request-redirect-mode
)
: "follow"
(the default), "error", and "manual".
Due to limitations of XMLHttpRequest, only the "follow" mode is available in
browsers where this polyfill is active.
#### Obtaining the Response URL
#### Obtaining the Response URL
Due to limitations of XMLHttpRequest, the
`response.url`
value might not be
Due to limitations of XMLHttpRequest, the
`response.url`
value might not be
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录