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

222
Vistas
jQuery - false if AJAX result is xyz not recognised

I am displaying a wizard form and at some stage have to check whether the entered property_code input value matches any record in the database. This is done via jQuery and AJAX call, which responds with either Valid or Invalid, based on which I may want to stop the user from being able to move to the next page of the wizard.

Now, this feature is supported by the smartwizard() plugin and should work, but there seems to be a jQuery issue when validating the AJAX response. I see the response is Invalid, yet the user can still move on to the next slide, suggesting there is a problem when returning true or false.

// Initialize the leaveStep event
$("#smartwizard").on("leaveStep", function(e, anchorObject, stepIndex, nextStepIndex, stepDirection) {
    // console
    console.log('LeaveStep - CurrentStepIndex: ' + stepIndex);

    // Property Info - checks if property exists before leaving step 1
    if (stepIndex == 1) {

        //check if property code already exists in system
        var property_code = $("#property_code").val();
        console.log('Checking if property code "' + property_code + '" already exists in DB');

        $.ajax({
            type: 'POST',
            url: '../../controllers/hom_check_property_code.php',
            data: 'action=check_property_code&property_code=' + property_code,
            success: function(response) {
                console.log('Property check response: ' + response);

                if (response == 'Invalid') {
                    console.log('Property code check failed');
                    return false;
                } else {
                    console.log('Property code check passed');
                    return true;
                }
            },
            error: function(xhr, status, error) {
                console.log('Ajax POST request failed.');
                console.error(xhr);
            }
        });
    }

    // navigate to next step
    console.log('Navigating from stepIndex ' + stepIndex + ' to ' + nextStepIndex + ', moving in stepDirection ' + stepDirection);
    return true;
});

I am not good with jquery / JS, hence would appreciate if someone could explain me where the problem is? I understand that returning false should stop the remainder of the script from that point onward, so not sure what I am doing wrong here.

Thanks

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