-
-
Save kirubz/10a05b72e42dead47371103c649544e1 to your computer and use it in GitHub Desktop.
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 postJson(method, url, params) { | |
| let xhr = new XMLHttpRequest(); | |
| xhr.open(method, url, true); | |
| xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); | |
| xhr.send(JSON.stringify(params)); | |
| xhr.onreadystatechange = function() { | |
| let status; | |
| let data; | |
| if (xhr.readyState === 4) { | |
| status = xhr.status; | |
| if (status === 200) { | |
| data = JSON.parse(xhr.responseText); | |
| console.log("success", data); | |
| } else { | |
| console.log("failed", status); | |
| } | |
| } | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment