diff options
author | n-peugnet <n.peugnet@free.fr> | 2019-06-13 20:39:22 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2019-10-20 19:47:21 +0200 |
commit | 5ce588f52955f321fc1e6430a2e534bee73ec3e9 (patch) | |
tree | c3f2e2aebce4777ea05bae8bf9248b90b83e188e | |
parent | 0968351067f99e8afc882d4237902642e608e6f5 (diff) | |
download | wcms-5ce588f52955f321fc1e6430a2e534bee73ec3e9.tar.gz wcms-5ce588f52955f321fc1e6430a2e534bee73ec3e9.zip |
first add of ajax form submission
(not tested)
-rw-r--r-- | assets/js/edit.js | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/assets/js/edit.js b/assets/js/edit.js index b0f8915..13c227b 100644 --- a/assets/js/edit.js +++ b/assets/js/edit.js @@ -11,7 +11,10 @@ window.onload = () => { inputs[i].oninput = changeHandler; } - form.onsubmit = submitHandler; + form.addEventListener("submit", function (event) { + event.preventDefault(); + submitHandler(this); + }); window.onkeydown = keyboardHandler; window.onbeforeunload = confirmExit; @@ -51,10 +54,22 @@ function changeHandler(e) { /** * Manage submit event - * @param {Event} e + * @param {HTMLFormElement} form */ -function submitHandler(e) { +function submitHandler(form) { unsavedChanges = false; + + var xhr = new XMLHttpRequest(); + var fd = new FormData(form); + + xhr.addEventListener("load", function(event) { + alert(event.target.responseText); + }); + xhr.addEventListener("error", function(event) { + alert('Oups! Quelque chose s\'est mal passé.'); + }); + xhr.open(form.method, form.action); + xhr.send(fd); } /** |