I've built an online multiple choice quiz, where the user clicks on the desired answer of each question, and a $.post AJAX request is sent to the server for further processing.
For all questions except for the last one, the server script simply exit;s...
For the last question in particular, the server responds with the valid answers he/she gave (an echo $valid; and exit;s). Keep in mind that $valid may also be 0, if he/she didn't give any correct answers...
So, in the AJAX response function I have this
success: function(response) {
$(this).addClass('chosen').removeClass('loading-gif');
if (response !== null) {
countdown(response);
}
}
where countdown() prints a Thank you, you gave x out y valid answers message on the screen, does a live countdown effect, and then redirects to another page...
The problem is that no matter what I tried for the if check, it always shows the thank you message, even from the first answer... So I tried if (response !== null), if (typeof(response) !== 'undefined') and still I get the message... What I didn't try is if (response) because 0 evaluates to false, so in the case the user ends the test with 0 valid answers, the message won't show up...
Am I missing something? Why is this happening?