Created
July 30, 2015 21:37
-
-
Save jeffskelton3/3594505b33576f179e03 to your computer and use it in GitHub Desktop.
a vanilla js ajax get request
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 ajaxRequest(url, onSuccess, onError){ | |
| var xmlhttp = new XMLHttpRequest(), | |
| response = null; | |
| xmlhttp.onreadystatechange = function() { | |
| if (xmlhttp.readyState == 4) { | |
| if(xmlhttp.status == 200){ | |
| response = JSON.parse(xmlhttp.responseText); | |
| onSuccess(response); | |
| } | |
| else { | |
| onError(xmlhttp.responseText); | |
| } | |
| } | |
| }; | |
| xmlhttp.open("GET", url, true); | |
| xmlhttp.send(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment