Skip to content

Instantly share code, notes, and snippets.

@ianaya89
Created January 22, 2015 03:30
Show Gist options
  • Save ianaya89/b4947632744a22d67188 to your computer and use it in GitHub Desktop.
Save ianaya89/b4947632744a22d67188 to your computer and use it in GitHub Desktop.
Ajax request with Vanilla JS
function ajax(type, url) {
var request = new XMLHttpRequest();
request.open(type, url, true);
request.onload = function() {
if (this.status >= 200 && this.status < 400) {
//succes.
var resp = this.response;
}
else {
//server error.
}
};
request.onerror = function() {
//error.
};
request.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment