It’s easy, haha, accumulate a little every day
Start by implementing a simple promise
<script> var fun = new Promise((resolve, reject) => { setTimeout(() => { console.log(111); }, 1000) console.log(' I created a new promise'); }) fun.then((x) => { console.log(x); }) </script>Copy the code
Promise to implement ajax
<script>
var myAjax = (url) => {
return new Promise((resolve, reject) => {
var xhr = new XMLHttpRequest()
xhr.open('get', url)
xhr.send(data)
xhr.onreadystatechange = () => {
if (xhr.status == 200 && readyState == 4) {
var json = JSON.parse(xhr.responseText)
resolve(json)
} else {
reject('error')
}
}
})
}
</script>
Copy the code
Incidentally ask have big guy to be able to push inside!!