Skip to content

Instantly share code, notes, and snippets.

@loretoparisi
Created May 23, 2017 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loretoparisi/ec31270068c8f65881fbb27f9a906bf4 to your computer and use it in GitHub Desktop.
Save loretoparisi/ec31270068c8f65881fbb27f9a906bf4 to your computer and use it in GitHub Desktop.
XMLHttpRequest POST Minimal Example
SimpleRequest = {
call: function(what, response) {
var request;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
request = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try {
request = new ActiveXObject('Microsoft.XMLHTTP');
} catch (e) {}
}
}
request.onreadystatechange = function() {
if (request.readyState === 4) {
if (request.status === 200) {
response(request.responseText)
} else response();
}
}
request.open('POST', what, true);
var body={
}
request.send(JSON.stringify(body));
request.setRequestHeader("Content-Type", "application/json");
}
}
SimpleRequest.call('http://posttestserver.com/post.php', function(result) {
console.log("Response", result);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment