Skip to content

Instantly share code, notes, and snippets.

@loktar00
Created October 5, 2012 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save loktar00/3837820 to your computer and use it in GitHub Desktop.
Save loktar00/3837820 to your computer and use it in GitHub Desktop.
simple XMLHttpRequest
function post(url, data, callback){
var ajaxRequest = new XMLHttpRequest();
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4 || ajaxRequest.readyState == 200){
callback(ajaxRequest.responseText);
}
}
ajaxRequest.open("POST", url);
ajaxRequest.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
ajaxRequest.send(JSON.stringify(data));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment