Skip to content

Instantly share code, notes, and snippets.

@jeffskelton3
Created July 30, 2015 21:37
Show Gist options
  • Select an option

  • Save jeffskelton3/3594505b33576f179e03 to your computer and use it in GitHub Desktop.

Select an option

Save jeffskelton3/3594505b33576f179e03 to your computer and use it in GitHub Desktop.
a vanilla js ajax get request
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