美文网首页
Fetch函数

Fetch函数

作者: Cola1993a | 来源:发表于2017-08-30 09:42 被阅读9次
fetch(api.HN_ITEM_ENDPOINT+topStoryIDs[startIndex]+".json")
              .then((response) => response.json())
              .then((topStory) => {
                  topStory.count = startIndex+1;
                  rowsData.push(topStory);
                  startIndex++;
                  iterateAndFetch();
              })
              .done();
  • api.HN_ITEM_ENDPOINT+topStoryIDs[startIndex]+".json"-----------URL
  • (response) => response.json()到底做了什么
    返回的响应是JSON格式的,所以调用response.json方法来转换数据。还有其他方法来处理不同类型的响应。如果请求一个XML格式文件,则调用response.text。如果请求图片,使用response.blob方法。
  • topStory就是我们获取的数据
    接着对数据进行处理

相关文章

网友评论

      本文标题:Fetch函数

      本文链接:https://www.haomeiwen.com/subject/ylyzdxtx.html