Created
April 11, 2018 10:15
-
-
Save FagnerMartinsBrack/966cf0d1b72bf92edf046042eaa5271c to your computer and use it in GitHub Desktop.
(Medium) - Commands And Events
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
<div id="content"> | |
<form method="POST" action="http://server.example.com/"> | |
<input type="text" name="username"> | |
<input type="submit" value="Send POST command with username"> | |
<input type="button" onclick="submitUsername()" value="Send POST command with username using AJAX"> | |
</form> | |
</div> | |
<script> | |
function submitUsername() { | |
return fetch('http://server.example.com', { method: 'POST' }) | |
.then((response) => { response.text() }) | |
.then((responseBody) => { | |
document.getElementById('content').innerHTML = responseBody; | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment