Skip to content

Instantly share code, notes, and snippets.

@halexandra
Created October 3, 2017 08:48
Show Gist options
  • Select an option

  • Save halexandra/8d182b04a1dd4effbcf77384dc9ac7ea to your computer and use it in GitHub Desktop.

Select an option

Save halexandra/8d182b04a1dd4effbcf77384dc9ac7ea to your computer and use it in GitHub Desktop.

Revisions

  1. halexandra created this gist Oct 3, 2017.
    23 changes: 23 additions & 0 deletions rsvp.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    var getUsers = function(url) {
    var promise = new RSVP.Promise(function(resolve, reject){
    var client = new XMLHttpRequest();
    client.open("GET", url);
    client.onreadystatechange = handler;
    client.responseType = "json";
    client.setRequestHeader("Accept", "application/json");
    client.send();

    function handler() {
    if (this.readyState === this.DONE) {
    if (this.status === 200) { resolve(this.response); }
    else { reject(this); }
    }
    }
    });

    return promise;
    };

    getUsers('https://jsonplaceholder.typicode.com/users').then(function (response) {
    console.log(response);
    });