function sendXhr(url, method = 'GET', handle) {
const xhr = new XMLHttpRequest()
xhr.open(method, url)
xhr.onreadystatechange(() => {
if (this.readystate !== 4) {
return
} else {
if (this.status === 200) {
handle(this.response)
} else {
throw new Error(this.statusText)
}
}
})
xhr.onerror(() => {
throw new Error(this.statusText)
})
try {
xhr.send()
} catch(e) {
console.log(e)
}
}