Created
October 23, 2014 07:33
-
-
Save dvidsilva/0cdf7ba248e55c8c075b to your computer and use it in GitHub Desktop.
Creating an XHR request with JavaScript
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
function ajax() { | |
var xmlhttp; | |
xmlhttp = new XMLHttpRequest(); | |
xmlhttp.onreadystatechange = function() { | |
if (xmlhttp.readyState == 4 ) { | |
if(xmlhttp.status == 200){ | |
document.getElementById("response").innerHTML = xmlhttp.responseText; | |
} | |
else if(xmlhttp.status == 400) { | |
alert('There was an error 400'); | |
} | |
else { | |
alert('something else other than 200 was returned'); | |
} | |
} | |
} | |
xmlhttp.open("GET", "/ajax", true); | |
xmlhttp.send(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment