From 9ede50983959fa68e2f3e636910b0d339c517459 Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 28 Jan 2021 10:58:03 +0000 Subject: [PATCH] update posting answers to server --- js/interact.js | 51 ++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/js/interact.js b/js/interact.js index cefee76..085142a 100644 --- a/js/interact.js +++ b/js/interact.js @@ -4,7 +4,11 @@ export function submitAnswers(window, db) { console.log( 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 */ export function postAnswers(ans) { - $("#progress").html(`Submitting answers...`); + $("#progress").html("Submitting answers..."); // 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); if (data.success) { if (data.question_count == window.number_of_questions) { @@ -61,25 +66,27 @@ export function postAnswers(ans) { } } else { alert(`Error submitting answers: ${data.error}`); - var docHeight = $(document).height(); + var docHeight = $(document).height(); - $("body").append(`

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.

${JSON.stringify(ans)}
`); + $("body").append( + `

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.

${JSON.stringify( + ans + )}
` + ); - $("#overlay") - .height(docHeight) - .css({ - 'opacity' : 0.9, - 'position': 'absolute', - 'top': 0, - 'left': 0, - 'background-color': 'black', - 'width': '100%', - 'user-select': 'text', - '-moz-user-select': 'text', - '-webkit-user-select': 'text', - 'z-index': 5000 - }); - } - }); - // $.post( "http://localhost:8000/submit_answers", JSON.stringify(ans)); + $("#overlay").height(docHeight).css({ + opacity: 0.9, + position: "absolute", + top: 0, + left: 0, + "background-color": "black", + width: "100%", + "user-select": "text", + "-moz-user-select": "text", + "-webkit-user-select": "text", + "z-index": 5000, + }); + } + }); + // $.post( "http://localhost:8000/submit_answers", JSON.stringify(ans)); }