Skip to content

Instantly share code, notes, and snippets.

@myvyang
Created September 7, 2017 06:22
Show Gist options
  • Save myvyang/d6c02ec42624347d3d6985f2163875f7 to your computer and use it in GitHub Desktop.
Save myvyang/d6c02ec42624347d3d6985f2163875f7 to your computer and use it in GitHub Desktop.
function request(url, method, data, callback) {
function ready() {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
callback(httpRequest.responseText);
}
}
}
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = ready;
httpRequest.open(method, url);
if (method == "POST") {
httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
}
httpRequest.send(data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment