whatwg-fetch中fetch得到的response调用的.json()得到的数据类型是什么?

fetch('/users.html')
  .then(function(response) {
    return response.text()
  }).then(function(body) {
    document.body.innerHTML = body
  })    fetch('/users.json').then(function(response) {
      console.log(response.headers.get('Content-Type'))
      console.log(response.headers.get('Date'))
      console.log(response.status)
      console.log(response.statusText)
    })

上面是官方文档给的例子response.text()得到的是什么?.text()方法是在哪里定义的?


fetch('/users.json')
  .then(function(response) {
    return response.json()
  }).then(function(json) {
    console.log('parsed json', json)
  }).catch(function(ex) {
    console.log('parsing failed', ex)
  })

response.json()得到的是什么?.json()方法是在哪里定义的?

阅读 11.1k
2 个回答
新手上路,请多包涵

楼上的地址是没毛病的,但是说法却是有且概括,我按照你的说法尝试了一下,是报错的,还是去自仔细看看楼上给的地址中的源码吧

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题