The easiest way to do a POST in JavaScript: using fetch.
http://gengns.com/wp-content/uploads/2015/05/logo-onepage-300x66.png00Génesishttp://gengns.com/wp-content/uploads/2015/05/logo-onepage-300x66.pngGénesis2016-10-26 14:30:422016-10-26 18:21:22Post JSON data to an URL
Glad to see you here again 🙂 You are right, with your code we get the echo answer, JSFiddle web services need that ‘json=’ in the payload for that (they implemented it that way). However, I wanted it to keep it much simpler and generic. Thanks, you always write great comments xD
/* with jsfiddle’s echo replay */
const $div = document.querySelector(‘div’);
fetch(‘/echo/json/’, {
method: ‘post’,
body: “json=” + JSON.stringify({
animal: ‘dog’
})
})
.then(response => {
if (response.ok) response.json().then(json => $div.textContent = JSON.stringify(json));
else alert(response.statusText);
});
Glad to see you here again 🙂 You are right, with your code we get the echo answer, JSFiddle web services need that ‘json=’ in the payload for that (they implemented it that way). However, I wanted it to keep it much simpler and generic. Thanks, you always write great comments xD