in public/js/comment.js [3:49]
async function sendComment(f) {
var comment = {
id: f.id.value,
text: f.commentarea.innerHTML,
plainText: htmltoText(f.commentarea.innerHTML)
};
if (f.slug && f.slug.value) {
comment.slug = f.slug.value;
}
if (f.date && f.date.value) {
comment.date = f.date.value;
}
try {
var response = await fetch('comment/', {
method: 'POST',
credentials: 'include',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json',
'CSRF-Token': csrfToken
},
body: JSON.stringify(comment),
});
} catch (e) {
//console.log('fetch failed ' + e)
}
if (response.ok) {
try {
var json = await response.json();
if (json.ok) {
if(f.slug) {
//f.wys.destroy();
//f.remove();
} else {
f.wys.setValue('');
}
setComments(f.id.value, json.ret);
} else {
alert('Error adding comment: ' + json.msg);
}
} catch (e) {
alert('Error adding comment. Please reload the page and try again' + e + JSON.stringify(response));
}
} else {
alert('Failed to add comment. Please reload the page and try again');
}
}