c85a51e8788e85a3383c4171fdc04ce250560eea.svn-base 503 B

12345678910111213141516171819202122
  1. function XHR(url) {
  2. return new Promise(function(resolve, reject) {
  3. var xhr = new XMLHttpRequest();
  4. xhr.open('GET', url);
  5. xhr.onload = function() {
  6. if (xhr.status === 200) {
  7. resolve(xhr.responseText);
  8. } else {
  9. reject(new Error(xhr.statusText));
  10. }
  11. };
  12. xhr.onerror = function() {
  13. reject(new Error("Network Error"));
  14. };
  15. xhr.send();
  16. });
  17. }
  18. module.exports = XHR;