Last active
March 23, 2018 08:19
-
-
Save ttristan/c05b9a7352500f0a77b28bd916151772 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
// JS | |
function request() { | |
const xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function() { | |
if (xhr.readyState == XMLHttpRequest.DONE ) { | |
console.log("xhr response", xhr.response) | |
if (xhr.status == 200) { // success | |
} | |
else if (xhr.status == 400) { // error 400 (bad request) | |
} | |
else { // error | |
} | |
} | |
}; | |
const data = { | |
name: "Tristan", | |
value: "dev", | |
} | |
xhr.open("POST", "./search.php"); | |
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); | |
xhr.send(JSON.stringify(data)); | |
} | |
// PHP | |
<?php | |
$data = json_decode(file_get_contents('php://input'), true); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment