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()方法是在哪里定义的?
response.text()
获得文本类型的,源代码:https://github.com/github/fet...response.json()
会帮助你运行一次JSON.parse(response.text()),源代码:https://github.com/github/fet...