Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save amitgupta15/753a94f45e0554ce56f549e4312d4c4d to your computer and use it in GitHub Desktop.
Save amitgupta15/753a94f45e0554ce56f549e4312d4c4d to your computer and use it in GitHub Desktop.
$myapp.get = function (url, callback) {
var requestListener = function () {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
var response = JSON.parse(httpRequest.response);
callback(response);
} else {
alert('There was a problem with the request');
}
}
};
var httpRequest = new XMLHttpRequest();
httpRequest.addEventListener('load', requestListener);
httpRequest.open('GET', url);
httpRequest.send();
};
$myapp.getUser = function (id) {
$myapp.get('/api/users?id=' + id, function (user) {
var domElement = document.querySelector('#user-detail');
if (user) {
domElement.innerHTML = user.fname + ' ' + user.lname;
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment