Skip to content

Instantly share code, notes, and snippets.

@naithar
Last active March 3, 2017 13:41
Show Gist options
  • Save naithar/b6ecae073a31ba12bde1e85cdf2fd248 to your computer and use it in GitHub Desktop.
Save naithar/b6ecae073a31ba12bde1e85cdf2fd248 to your computer and use it in GitHub Desktop.
function webRequest(url, data, callback, target) {
var http = new XMLHttpRequest();
if(!data){ mode="GET"; } else { mode="POST"; }
http.open(mode, url, true);
if(mode=="POST"){ http.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); }
http.onreadystatechange = function(){ if(http.readyState==4){ callback(http.responseText,target); }};
http.send(data);
}
//http://stackoverflow.com/questions/247483/http-get-request-in-javascript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment