req.js 433 B

12345678910111213141516
  1. function getJSON(url){
  2. return new Promise( function(resolve, reject){
  3. var xhr = new XMLHttpRequest();
  4. xhr.open('get',url,true);
  5. xhr.responseType ='json';
  6. xhr.onload = function(){
  7. var status = xhr.status;
  8. if (status == 200) {
  9. resolve(xhr.response);
  10. } else {
  11. reject(status);
  12. }
  13. };
  14. xhr.send();
  15. });
  16. };