Created
November 24, 2011 07:17
-
-
Save motyar/1390818 to your computer and use it in GitHub Desktop.
Simplest AJAX call with Raw JavaScript
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
window.onload = function(){ | |
var xhr; | |
if(typeof XMLHttpRequest !== 'undefined') xhr = new XMLHttpRequest(); | |
else { | |
var versions =["MSXML2.XmlHttp.5.0","MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.3.0","MSXML2.XmlHttp.2.0","Microsoft.XmlHttp"]; | |
for(var i = 0, len = versions.length; i < len; i++) { | |
try { | |
xhr = new ActiveXObject(versions[i]); | |
break; | |
} | |
catch(e){} | |
} // end for | |
} | |
xhr.onreadystatechange = ensureReadiness; | |
function ensureReadiness() { | |
if(xhr.readyState < 4) { | |
return; | |
} | |
if(xhr.status !== 200) { | |
return; | |
} | |
// all is well | |
if(xhr.readyState === 4) { | |
alert(xhr.responseText); | |
} | |
} | |
xhr.open('GET', 'https://graph.facebook.com/motyar', true); | |
xhr.send(''); | |
}; | |
//Check working example at http://jsbin.com/aqumup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great artice..
Is still in use or new changes done? suggest any other framework for async call.. like angular, knockout..
Is this RA ajax?