Skip to content

Instantly share code, notes, and snippets.

@willread
Created August 21, 2012 20:20
Show Gist options
  • Save willread/3419026 to your computer and use it in GitHub Desktop.
Save willread/3419026 to your computer and use it in GitHub Desktop.
Minimal cross browser AJAX
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
});
@romainbessugesmeusy
Copy link

Hey, that's a nice snippet. Do you know in which browsers this code is actually working ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment