Created
January 22, 2015 03:30
-
-
Save ianaya89/b4947632744a22d67188 to your computer and use it in GitHub Desktop.
Ajax request with Vanilla JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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