Created
September 7, 2017 06:22
-
-
Save myvyang/d6c02ec42624347d3d6985f2163875f7 to your computer and use it in GitHub Desktop.
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
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