12345678910111213141516171819202122 |
- function XHR(url) {
- return new Promise(function(resolve, reject) {
- var xhr = new XMLHttpRequest();
- xhr.open('GET', url);
- xhr.onload = function() {
- if (xhr.status === 200) {
- resolve(xhr.responseText);
- } else {
- reject(new Error(xhr.statusText));
- }
- };
- xhr.onerror = function() {
- reject(new Error("Network Error"));
- };
- xhr.send();
- });
- }
- module.exports = XHR;
|