Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!