Skip to content

Instantly share code, notes, and snippets.

@AVGP
Created February 28, 2020 21:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AVGP/9717aeba9e9979fb1a83a982504bb82e to your computer and use it in GitHub Desktop.
Save AVGP/9717aeba9e9979fb1a83a982504bb82e to your computer and use it in GitHub Desktop.
<?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