Created
August 21, 2012 20:20
-
-
Save willread/3419026 to your computer and use it in GitHub Desktop.
Minimal cross browser AJAX
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 minimalAjax = function(url, callback){ | |
var xmlHTTP = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MicrosoftXMLHTTP"); | |
xmlHTTP.onreadystatechange = function(){ | |
if(this.readyState == 4 && this.status == 200) | |
callback(this.responseText); | |
} | |
xmlHTTP.open("GET", url, true); | |
xmlHTTP.send(); | |
} | |
minimalAjax("http://www.url.com", function(data){ | |
// Got some data | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, that's a nice snippet. Do you know in which browsers this code is actually working ?