<bdo id='BWM8o'></bdo><ul id='BWM8o'></ul>

    <legend id='BWM8o'><style id='BWM8o'><dir id='BWM8o'><q id='BWM8o'></q></dir></style></legend>
  1. <tfoot id='BWM8o'></tfoot>

    <small id='BWM8o'></small><noframes id='BWM8o'>

      <i id='BWM8o'><tr id='BWM8o'><dt id='BWM8o'><q id='BWM8o'><span id='BWM8o'><b id='BWM8o'><form id='BWM8o'><ins id='BWM8o'></ins><ul id='BWM8o'></ul><sub id='BWM8o'></sub></form><legend id='BWM8o'></legend><bdo id='BWM8o'><pre id='BWM8o'><center id='BWM8o'></center></pre></bdo></b><th id='BWM8o'></th></span></q></dt></tr></i><div id='BWM8o'><tfoot id='BWM8o'></tfoot><dl id='BWM8o'><fieldset id='BWM8o'></fieldset></dl></div>

    1. 获取 API 与 XMLHttpRequest

      时间:2023-10-15
        <tbody id='cFOOV'></tbody>

      <small id='cFOOV'></small><noframes id='cFOOV'>

        <tfoot id='cFOOV'></tfoot>

            • <i id='cFOOV'><tr id='cFOOV'><dt id='cFOOV'><q id='cFOOV'><span id='cFOOV'><b id='cFOOV'><form id='cFOOV'><ins id='cFOOV'></ins><ul id='cFOOV'></ul><sub id='cFOOV'></sub></form><legend id='cFOOV'></legend><bdo id='cFOOV'><pre id='cFOOV'><center id='cFOOV'></center></pre></bdo></b><th id='cFOOV'></th></span></q></dt></tr></i><div id='cFOOV'><tfoot id='cFOOV'></tfoot><dl id='cFOOV'><fieldset id='cFOOV'></fieldset></dl></div>
              • <bdo id='cFOOV'></bdo><ul id='cFOOV'></ul>

              • <legend id='cFOOV'><style id='cFOOV'><dir id='cFOOV'><q id='cFOOV'></q></dir></style></legend>

                本文介绍了获取 API 与 XMLHttpRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我知道 Fetch API 使用 Promise 并且它们都允许您向服务器发出 AJAX 请求.

                I know that Fetch API uses Promises and both of them allow you to do AJAX requests to a server.

                我了解到 Fetch API 有一些额外的功能,这些功能在 XMLHttpRequest 中不可用(在 Fetch API polyfill 中,因为它基于 XHR).

                I have read that Fetch API has some extra features, which aren't available in XMLHttpRequest (and in the Fetch API polyfill, since it's based on XHR).

                Fetch API 有哪些额外功能?

                What extra capabilities does the Fetch API have?

                推荐答案

                有些事情你可以用 fetch 而不是 XHR:

                There are a few things that you can do with fetch and not with XHR:

                • 您可以将缓存 API 与请求和响应对象一起使用;
                • 您可以执行 no-cors 请求,从未实现 CORS 的服务器获取响应.您无法直接从 JavaScript 访问响应正文,但您可以将其与其他 API(例如缓存 API)一起使用;
                • 流式响应(使用 XHR,整个响应缓冲在内存中,使用 fetch 您将能够访问低级流).尚未在所有浏览器中提供此功能,但很快就会提供.
                • You can use the Cache API with the request and response objects;
                • You can perform no-cors requests, getting a response from a server that doesn't implement CORS. You can't access the response body directly from JavaScript, but you can use it with other APIs (e.g. the Cache API);
                • Streaming responses (with XHR the entire response is buffered in memory, with fetch you will be able to access the low-level stream). This isn't available yet in all browsers, but will be soon.

                你可以用 XHR 做一些你不能用 fetch 做的事情,但它们迟早会可用(阅读此处的未来改进"段落:https://hacks.mozilla.org/2015/03/this-api-就是这么拿取/):

                There are a couple of things that you can do with XHR that you can't do yet with fetch, but they're going to be available sooner or later (read the "Future improvements" paragraph here: https://hacks.mozilla.org/2015/03/this-api-is-so-fetching/):

                • 中止请求(这现在可以在 Firefox 和 Edge 中使用,正如 @sideshowbarker 在他的评论中解释的那样);
                • 报告进度.

                本文https://jakearchibald.com/2015/thats-so-fetch/ 包含更详细的描述.

                This article https://jakearchibald.com/2015/thats-so-fetch/ contains a more detailed description.

                这篇关于获取 API 与 XMLHttpRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:IE8/9 中的表单数据 下一篇:fetch - multipart/form-data POST 中缺少边界

                相关文章

                最新文章

              • <legend id='WTC5h'><style id='WTC5h'><dir id='WTC5h'><q id='WTC5h'></q></dir></style></legend>

              • <small id='WTC5h'></small><noframes id='WTC5h'>

              • <i id='WTC5h'><tr id='WTC5h'><dt id='WTC5h'><q id='WTC5h'><span id='WTC5h'><b id='WTC5h'><form id='WTC5h'><ins id='WTC5h'></ins><ul id='WTC5h'></ul><sub id='WTC5h'></sub></form><legend id='WTC5h'></legend><bdo id='WTC5h'><pre id='WTC5h'><center id='WTC5h'></center></pre></bdo></b><th id='WTC5h'></th></span></q></dt></tr></i><div id='WTC5h'><tfoot id='WTC5h'></tfoot><dl id='WTC5h'><fieldset id='WTC5h'></fieldset></dl></div>
                  <bdo id='WTC5h'></bdo><ul id='WTC5h'></ul>
              • <tfoot id='WTC5h'></tfoot>