diff --git a/QuizTheWord/app.py b/QuizTheWord/app.py index dfbea62..9573fc9 100644 --- a/QuizTheWord/app.py +++ b/QuizTheWord/app.py @@ -84,7 +84,7 @@ def next_hidden_answer(): return jsonify(next_question.get_dict()) else: session.pop("hidden_answer_ids", None) - return jsonify(None) + return jsonify(None), 204 @app.route("/category/multiple_choice/next_question") @@ -99,7 +99,7 @@ def next_multiple_choice(): return jsonify(next_question.get_dict_shuffled_choices()) else: session.pop("multiple_choice_ids", None) - return jsonify(None) + return jsonify(None), 204 @app.route("/login", methods=["GET", "POST"]) diff --git a/QuizTheWord/static/js/script.js b/QuizTheWord/static/js/script.js index 7971491..5fe45ec 100644 --- a/QuizTheWord/static/js/script.js +++ b/QuizTheWord/static/js/script.js @@ -19,7 +19,16 @@ function get_new_question(difficulty) { dataType: "json", success: (data, textStatus, jqXHR) => { control_btns.attr("disabled", false); - question_received(data); + if (textStatus !== "nocontent") { + question_received(data); + } else { + question_received(textStatus); + } + }, + error: (jqXHR, textStatus, errorThrown) => { + control_btns.attr("disabled", false); + console.log(textStatus); + console.log(errorThrown); }, }) } @@ -57,11 +66,13 @@ function previous_question() { function question_received(data) { let difficulty = questions[current_difficulty-1]; if (data) { - difficulty["questions"].push(data); - difficulty["current_question"] += 1; - update_question(); - } else { - difficulty["last_index"] = difficulty["current_question"]; - update_question(); + if (data !== "nocontent") { + difficulty["questions"].push(data); + difficulty["current_question"] += 1; + update_question(); + } else { + difficulty["last_index"] = difficulty["current_question"]; + update_question(); + } } }