Skip to content

Instantly share code, notes, and snippets.

@calebrob6
Created December 6, 2012 20:53
Show Gist options
  • Save calebrob6/4228239 to your computer and use it in GitHub Desktop.
Save calebrob6/4228239 to your computer and use it in GitHub Desktop.
Sending POST data
http = new XMLHttpRequest();
var params = "lorem=ipsum&name=binny";
http.open("POST", "http://localhost:8080/", true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
console.debug(http.responseText);
}
}
http.send(params);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment