Skip to content

Instantly share code, notes, and snippets.

@erwan
Created January 23, 2013 08:27
Show Gist options
  • Save erwan/4603137 to your computer and use it in GitHub Desktop.
Save erwan/4603137 to your computer and use it in GitHub Desktop.
if (typeof $ === "undefined") {
var $ = {
ajax(url, params) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if(xhr.readyState < 4) {
return;
}
if(xhr.status !== 200) {
if (params.error) {
params.error();
}
return;
}
if(xhr.readyState === 4) {
if (params.success) {
params.success();
}
}
}
xhr.open('GET', params.url, true);
xhr.send('');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment