update posting answers to server

This commit is contained in:
Ross
2021-01-28 10:58:03 +00:00
parent f7fc1d9134
commit 9ede509839
+29 -22
View File
@@ -4,7 +4,11 @@
export function submitAnswers(window, db) { export function submitAnswers(window, db) {
console.log( console.log(
getJsonAnswers(window, db).then((a) => { getJsonAnswers(window, db).then((a) => {
postAnswers(a); let json = {
"eid": window.eid,
"answers": JSON.stringify(a),
};
postAnswers(json);
}) })
); );
} }
@@ -28,9 +32,10 @@ export function getJsonAnswers(window, db) {
* @param {*} ans - json representation of answers * @param {*} ans - json representation of answers
*/ */
export function postAnswers(ans) { export function postAnswers(ans) {
$("#progress").html(`Submitting answers...`); $("#progress").html("Submitting answers...");
// ans = {"test" : 1} // ans = {"test" : 1}
$.post(window.config.exam_submit_url, JSON.stringify(ans)).done((data) => { console.log(ans)
$.post(window.config.exam_submit_url, ans, null, "json").done((data) => {
console.log(data); console.log(data);
if (data.success) { if (data.success) {
if (data.question_count == window.number_of_questions) { if (data.question_count == window.number_of_questions) {
@@ -61,25 +66,27 @@ export function postAnswers(ans) {
} }
} else { } else {
alert(`Error submitting answers: ${data.error}`); alert(`Error submitting answers: ${data.error}`);
var docHeight = $(document).height(); var docHeight = $(document).height();
$("body").append(`<div id='overlay'><span style='color: white'><p>An error has occured when submit your answers. A copy of your answers are displayed below, you may wish to save a copy. Please refresh this page to continue.</p>${JSON.stringify(ans)}</span></div>`); $("body").append(
`<div id='overlay'><span style='color: white'><p>An error has occured when submit your answers. A copy of your answers are displayed below, you may wish to save a copy. Please refresh this page to continue.</p>${JSON.stringify(
ans
)}</span></div>`
);
$("#overlay") $("#overlay").height(docHeight).css({
.height(docHeight) opacity: 0.9,
.css({ position: "absolute",
'opacity' : 0.9, top: 0,
'position': 'absolute', left: 0,
'top': 0, "background-color": "black",
'left': 0, width: "100%",
'background-color': 'black', "user-select": "text",
'width': '100%', "-moz-user-select": "text",
'user-select': 'text', "-webkit-user-select": "text",
'-moz-user-select': 'text', "z-index": 5000,
'-webkit-user-select': 'text', });
'z-index': 5000 }
}); });
} // $.post( "http://localhost:8000/submit_answers", JSON.stringify(ans));
});
// $.post( "http://localhost:8000/submit_answers", JSON.stringify(ans));
} }