JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" id="text"/>
<button onclick="laheta()">Lähetä!</button>
<p id="received">
</p>
JavaScript
var url = "https://jsonplaceholder.typicode.com/posts"
var http = new XMLHttpRequest()
http.onreadystatechange = function() {
if (this.readyState != 4) {
return
}
document.getElementById("received").innerHTML = this.responseText
}
function laheta() {
var data = {
title: document.getElementById("text").value,
body: "hello world"
}
http.open("POST", url)
http.send(JSON.stringify(data))
}