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

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

      1. <tfoot id='xVHRX'></tfoot>
        • <bdo id='xVHRX'></bdo><ul id='xVHRX'></ul>

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

        fetch().then() 返回内容类型和正文

        fetch().then() return content-type and body(fetch().then() 返回内容类型和正文)
        <tfoot id='in6Vq'></tfoot>
            <tbody id='in6Vq'></tbody>
            <bdo id='in6Vq'></bdo><ul id='in6Vq'></ul>

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

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

                1. 本文介绍了fetch().then() 返回内容类型和正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  互联网上的每个 fetch API 示例都展示了如何使用 response.json()、response.blob() 等仅返回正文.我需要的是调用一个同时具有内容类型和主体作为 blob 的函数,但我不知道该怎么做.

                  Every fetch API example on the internet shows how to return only the body using response.json(), response.blob() etc. What I need is to call a function with both the content-type and the body as a blob and I cannot figure out how to do it.

                  fetch("url to an image of unknown type")
                    .then((response) => {
                      return {
                        contentType: response.headers.get("Content-Type"),
                        raw: response.blob()
                    })
                    .then((data) => {
                      imageHandler(data.contentType, data.raw);
                    });
                  

                  这显然不起作用:data.contentType 已填充,但 data.raw 是一个承诺.如何在同一上下文中获取这两个值?

                  This obviously doesn't work: data.contentType is filled, but data.raw is a promise. How can I get both values in the same context?

                  推荐答案

                  你可以这样写:

                  fetch("url to an image of unknown type")
                    .then(response => {
                      return response.blob().then(blob => {
                        return {
                          contentType: response.headers.get("Content-Type"),
                          raw: blob
                        }
                      })
                    })
                    .then(data => {
                      imageHandler(data.contentType, data.raw);
                    });
                  

                  或者这样

                  fetch("url to an image of unknown type")
                    .then(response => {
                      return response.blob().then(blob => {
                          imageHandler(response.headers.get("Content-Type"), blob)
                      })
                    })
                  

                  在这两种情况下,您都将收到已解析的 blob 的回调保留在您有权访问 response 的范围内.

                  In both cases you keep the callback in which you receive the resolved blob within the scope where you have access to response.

                  这篇关于fetch().then() 返回内容类型和正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  业务场景:使用update语句去更新数据库字段。 原因:update接收值不正确。原来代码: $query = "UPDATE student SET date = now() WHERE id = $id";$result = $mysqli-query($query2) or die($mysqli-error); // 问题出现了在这句 $data = $result-fetch_ass
                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)

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

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