dataURI + XHR
let xhr = new XMLHttpRequest()
xhr.open('GET', 'data:text/json,{"a":123}', true)
xhr.onreadystatechange = () => {
if (xhr.readyState !== 4) return ''
console.log('xhr.readyState: ' + xhr.readyState)
console.log('xhr.status: ' + xhr.status)
console.log('xhr.responseText: ' + xhr.responseText)
}
xhr.send()
dataURI + base64 + XHR
let xhr = new XMLHttpRequest()
xhr.open('GET', 'data:text/json;base64,eyJhIjoxMjN9', true)
xhr.onreadystatechange = () => {
if (xhr.readyState !== 4) return ''
console.log('xhr.readyState: ' + xhr.readyState)
console.log('xhr.status: ' + xhr.status)
console.log('xhr.responseText: ' + xhr.responseText)
}
xhr.send()
dataURI + fetch
fetch('data:text/json,{"a":123}')
.then(function(res) {
// res.text() 和 res.json() 均会返回一个Promise对象
return res.json()
})
.then(function(data) {
console.log(data)
})