Created
January 23, 2017 08:45
-
-
Save Neshable/397bf62f7c4e26290a938d81408def78 to your computer and use it in GitHub Desktop.
JS Ajax Boilerplate
This file contains 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
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