xml
<script>
var promise = new Promise((resolve, reject) => {
//resolve成功的处理方式,reject失败的处理方式
})
function getJson(url) {
const promise = new Promise((reslove, reject) => {
//网络请求
const client = new XMLHttpRequest()
client.open("get", url)
client.responseType = "json"
client.send()
client.onreadystatechange = function() {
if (client.readyState === 4) {
if (client.status === 200) {
reslove(client.response)
} else {
reject(new Error(client.statusText))
}
}
}
})
return promise
}
</script>