Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

89
Vistas
Check AJAX response is set

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?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda