Skip to content

Instantly share code, notes, and snippets.

@Neshable
Created January 23, 2017 08:45
Show Gist options
  • Save Neshable/397bf62f7c4e26290a938d81408def78 to your computer and use it in GitHub Desktop.
Save Neshable/397bf62f7c4e26290a938d81408def78 to your computer and use it in GitHub Desktop.
JS Ajax Boilerplate
var ourRequest = new XMLHttpRequest();
ourRequest.open('GET', 'your-url');
ourRequest.onload = function() {
if (ourRequest.status >= 200 && ourRequest.status < 400) {
var data = JSON.parse(ourRequest.responseText);
} else {
console.log("Connected, but errors occurred.");
}
};
ourRequest.onerror = function() {
console.log("Connection error");
};
ourRequest.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment