Created
July 27, 2015 11:24
-
-
Save jkk/d057133bec382b19c913 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 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