Files
liquidjs/src/util/http.js
T
2018-08-20 23:58:41 +08:00

18 lines
443 B
JavaScript

export function get (url) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest()
xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 300) {
resolve(xhr.responseText)
} else {
reject(new Error(xhr.statusText))
}
}
xhr.onerror = () => {
reject(new Error('An error occurred whilst sending the response.'))
}
xhr.open('GET', url)
xhr.send()
})
}