Skip to navigation
Send text-area form-data via ajax with only javascript
27.09.18
window.onload = function () { delete_minmax.onsubmit=function() { var styles = document.getElementById('styles').value; var locations = document.getElementById('locations').value; if(styles.length && locations.length) { xdelete(styles.split('\n'),locations.split('\n')); } else { set_msg('missing input styles: '+ styles.length + 'x locations:' + locations.length + 'x'); } return false; } }; function set_msg(message) { var msg = document.getElementById('message'); var txt = document.createTextNode(message); if(msg.childNodes[0]){ msg.removeChild(msg.childNodes[0]); } msg.appendChild(txt); } function xdelete(styles,locations) { var xhr = new XMLHttpRequest(); xhr.open('DELETE', '{{url}}/min_max'); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.onload = function() { if(xhr.status === 200) { set_msg(xhr.responseText); } }; xhr.send(JSON.stringify({ styles: styles, locations: locations })); }
Styles:
Locations:
https://shellmonger.com/2015/03/24/promises-and-ajax-in-ecmascript-6/
Reply
Anonymous
Information Epoch 1753641941
Small is beautiful.
Home
Notebook
Contact us