Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FagnerMartinsBrack/966cf0d1b72bf92edf046042eaa5271c to your computer and use it in GitHub Desktop.
Save FagnerMartinsBrack/966cf0d1b72bf92edf046042eaa5271c to your computer and use it in GitHub Desktop.
(Medium) - Commands And Events
<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