var token = document.getElementById('token'); var message = document.getElementById('message'); var button = document.getElementById('notify'); function sendMessage() { fetch('https://mozcurius.herokuapp.com/notify', { method: 'POST', mode: 'cors', headers: { 'Content-type': 'application/json' }, body: JSON.stringify({ token: token.value, client: 'JSFiddle', payload: { title: 'Message from the bottle', body: message.value } }) }); } button.onclick = sendMessage;
<p> token: <input type="text" id="token"> </p> <p> message: <input type="text" id="message"> <button id="notify"> Notify Me! </button> </p> <p> Get your token at <a href="http://mozcurius.herokuapp.com/">Mercurius site</a>. </p>