Last active
November 28, 2019 18:16
-
-
Save onliniak/3fb72b2cdbd7d138b4a1ff3a1b5888dd to your computer and use it in GitHub Desktop.
JS Fetch API → send POST and display response
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
<?php | |
$json = file_get_contents('php://input'); | |
$obj = json_decode($json, true); | |
var_dump($obj); |
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
<div class="grid-container"> | |
<div id="main_window"></div> | |
<div class="radio"> | |
<fieldset> | |
<input type="radio" name="ID" style="display:none" checked> | |
<label><input type="radio" name="ID" onchange='sessionStorage.setItem("ID", "1");ajax();'>1</label> | |
<br> | |
<label><input type="radio" name="ID" onchange='sessionStorage.setItem("ID", "2");ajax();'>2</label> | |
<br> | |
</fieldset> | |
</div> |
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
fetch("/wp-content/plugins/test/check.php", { | |
method: "POST", | |
body: JSON.stringify({ | |
"ID": sessionStorage.getItem('ID'), | |
"time": time, | |
"data": date, | |
}) | |
}) | |
.then((res) => { | |
return res.text(); | |
}) | |
.then((data) => { | |
document.getElementById("main_window").innerHTML = data | |
}) |
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
.grid-container { | |
display: grid; | |
grid-template-columns: 800px 400px | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment