Created
October 3, 2017 08:48
-
-
Save halexandra/8d182b04a1dd4effbcf77384dc9ac7ea to your computer and use it in GitHub Desktop.
Revisions
-
halexandra created this gist
Oct 3, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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); });