Skip to content

Instantly share code, notes, and snippets.

@vladkosinov
Forked from RB-Lab/simple-ajax.js
Last active August 29, 2015 14:20
Show Gist options
  • Save vladkosinov/a49056008751edd8c456 to your computer and use it in GitHub Desktop.
Save vladkosinov/a49056008751edd8c456 to your computer and use it in GitHub Desktop.
function ajax(url, cb, errcb) {
var xhr;
xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
if (4 === xhr.readyState) {
if(xhr.status >= 200 && xhr.status < 400){
cb(xhr);
} else {
errcb(xhr);
}
}
};
xhr.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment