Created
February 28, 2020 21:40
-
-
Save AVGP/9717aeba9e9979fb1a83a982504bb82e 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
<?php | |
if( !empty( $_POST ) ) { | |
die( "data: " . $_POST["msg"] ); | |
} | |
?> | |
<form method="post"> | |
<button type="button">Go</button> | |
</form> | |
<script> | |
document.querySelector("button").addEventListener("click", function() { | |
var req = new XMLHttpRequest(); | |
req.open("POST", window.location.href, true) | |
req.onreadystatechange = function() { | |
if(req.readyState == 4) alert(req.responseText) | |
} | |
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); | |
req.send("msg=" + JSON.stringify([1,2,"hi"])) | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment