form submission changed to ajax

This commit is contained in:
Christian Müller
2017-09-23 23:29:06 +02:00
parent bd3e4a30af
commit 53f2dad4a2
7 changed files with 95 additions and 59 deletions
+20
View File
@@ -0,0 +1,20 @@
"use strict";
function post(url, vals, cb) {
var data = new FormData();
for (var key in vals) {
data.append(key, vals[key]);
}
var xhr = new XMLHttpRequest();
xhr.open('POST', url)
xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.DONE) return cb(xhr.status, xhr.responseText) };
xhr.send(data);
}
function report(id) {
var resp = prompt("Please shortly explain the problem with this note.");
if (resp) {
post('/' + id + '/report', { "report": resp })
alert("Thank you!")
}
}
+5
View File
@@ -272,3 +272,8 @@ form {
li {
margin: 0.3em 0;
}
#feedback {
margin-left: 1em;
color: #f66;
}