Created
May 23, 2017 16:57
-
-
Save loretoparisi/ec31270068c8f65881fbb27f9a906bf4 to your computer and use it in GitHub Desktop.
XMLHttpRequest POST Minimal Example
This file contains 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
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