Created
April 13, 2016 10:19
-
-
Save rampatra/969924215b724c19faf795497f7274ad to your computer and use it in GitHub Desktop.
Generic XML Http Request method in javascript
This file contains hidden or 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
function xhr(method, uri, body, handler) { | |
var req = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); | |
req.onreadystatechange = function () | |
{ | |
if (req.readyState == 4 && handler) | |
{ | |
eval('var o=' + req.responseText); | |
handler(o); | |
} | |
} | |
req.open(method, uri, true); | |
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | |
req.send(body); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You call the above method like this: