search

Home  >  Q&A  >  body text

javascript - Problems with ES7 fetch to obtain data

fetch('/static/data/data.json')
            .then(data => {
                console.log(data);
            })

But no data was returned to me. Where is the data?

typechotypecho2817 days ago752

reply all(3)I'll reply

  • 迷茫

    迷茫2017-06-26 10:52:50

    First of all, Fetch API is a Web API and has nothing to do with ES7.

    Regarding the Fetch API, it needs to cooperate with Request and Response. Here is a more detailed tutorial on how these APIs cooperate to complete the request.

    reply
    0
  • 女神的闺蜜爱上我

    女神的闺蜜爱上我2017-06-26 10:52:50

    See MDN:
    https://developer.mozilla.org... To make a fetch request
    you should use:

    data.blob()

    reply
    0
  • 欧阳克

    欧阳克2017-06-26 10:52:50

    fetch('/static/data/data.json')

            .then(data =>data.json())
            .then(json=>console.log(json))

    reply
    0
  • Cancelreply