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

        如何从 fetch javascript 请求的响应中获取数据

        how to get data from response from fetch javascript request(如何从 fetch javascript 请求的响应中获取数据)

          <tbody id='N0QzE'></tbody>
      1. <tfoot id='N0QzE'></tfoot>

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

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

                • 本文介绍了如何从 fetch javascript 请求的响应中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I make fetch request in javascript . It is fetching data when I seed console it show me data. but when I try to alert it in then function it displays empty. it show alert promptly with page load. I think it alerting before request response

                  Here is my javascript code

                  fetch("https://01b4e41e6262.ngrok.io/api/get_schedule_orders/" + gUser.getData().id).then(res => {
                          if (res.ok) {
                          alert(res)
                          }
                      });
                  

                  解决方案

                  fetch() returns a Promise initially, so res is initially a promise, either resolved or rejected. Then res.json() again returns a promise and not the value directly (You may verify this by doing a console.log(res) in the first then(), there in the prototype you will see json(), which is again Promise based.

                  That's why we chain promises by doing return res.json() and get our data in the second promise resolve and in case of rejection catch() callback is invoked.

                  fetch("https://01b4e41e6262.ngrok.io/api/get_schedule_orders/" + gUser.getData().id).then(res => {
                      if (res.status>=200 && res.status <300) {
                        return res.json()
                      }else{
                        throw new Error();
                      }
                  }).then(data=>console.log(data))
                   .catch(err=>console.log('fetch() failed'))
                  

                  UPDATE: your API is returning an empty array.

                  Please check the API params.

                  这篇关于如何从 fetch javascript 请求的响应中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Fetch multiple links inside foreach loop(在 foreach 循环中获取多个链接)
                  Backbone Fetch Request is OPTIONS method(Backbone Fetch Request 是 OPTIONS 方法)
                  Fetch API leaks memory in Chrome(Fetch API 在 Chrome 中泄漏内存)
                  How can I download and save a file using the Fetch API? (Node.js)(如何使用 Fetch API 下载和保存文件?(Node.js))
                  Send blob data to node using fetch, multer, express(使用 fetch、multer、express 将 blob 数据发送到节点)
                  Sending a custom User-Agent string along with my headers (fetch)(发送自定义用户代理字符串以及我的标头(获取))

                    <legend id='zijWs'><style id='zijWs'><dir id='zijWs'><q id='zijWs'></q></dir></style></legend>
                  • <tfoot id='zijWs'></tfoot>
                    • <bdo id='zijWs'></bdo><ul id='zijWs'></ul>

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

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