Skip to content

Instantly share code, notes, and snippets.

@ianaya89

ianaya89/ajax.js

Created Jan 22, 2015
Embed
What would you like to do?
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