Skip to content

Instantly share code, notes, and snippets.

@asunar
Created March 15, 2021 21:46
Show Gist options
  • Save asunar/2110e8a11760ff081fd0f3a8fc0343a0 to your computer and use it in GitHub Desktop.
Save asunar/2110e8a11760ff081fd0f3a8fc0343a0 to your computer and use it in GitHub Desktop.
<html>
<body>
<button type="submit" onclick="submit();">Submit</button>
</body>
<script>
function submit(){
fetch("<api_url>", {
// Adding method type
method: "POST",
// Adding body or contents to send
body: JSON.stringify({"message":" This is bad service"}),
// Adding headers to the request
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
// Converting to JSON
.then(response => response.json())
// Displaying results to console
.then(json => console.log(json));
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment