You're not sending the
POST
data:
function getText(){
var a = document.getElementById('text').value;
fetch ('chatdb.php', {
method: 'POST',
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: "chat=" + encodeURIComponent(a)
})
.then (response => response.text())
.then (responseText => {
document.getElementById('text').innerHTML = responseText;
})
.catch (console.error);
}
Using Fetch - Web APIs | MDN[
^]