Skip to content

Instantly share code, notes, and snippets.

@marcusshepp
Created April 10, 2016 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusshepp/7bda7bcd9d379b77bef87a3d16484562 to your computer and use it in GitHub Desktop.
Save marcusshepp/7bda7bcd9d379b77bef87a3d16484562 to your computer and use it in GitHub Desktop.
Vanilla Javascript AJAX Function
var http_request = new XMLHttpRequest();
http_request.open("GET", "{% url 'api_categories' %}");
http_request.send(null);
http_request.onreadystatechange = function(){
var DONE = 4;
var OK = 200;
if (http_request.readyState === DONE){
if (http_request.status === OK){
console.log(http_request.responseText);
} else {
console.log("Error: " + http_request.status);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment