Skip to content

Instantly share code, notes, and snippets.

@hdemon
Created August 28, 2011 11:38
Show Gist options
  • Save hdemon/1176569 to your computer and use it in GitHub Desktop.
Save hdemon/1176569 to your computer and use it in GitHub Desktop.
xhr.js
var xhr = function(){
var xhr = new XMLHttpRequest();
return function( method, url, param, callback ){
xhr.onreadystatechange = function(){
if ( xhr.readyState === 4 ){
callback( xhr.responseText );
}
};
xhr.open( method, url+(method==="get" ? "?"+param : ""), true );
xhr.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
xhr.send( method==="post" ? param : "" );
};
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment