Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3397012
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:28:38+00:00 2026-05-18T04:28:38+00:00

Hello I am working with an ajax post function, where I send data and

  • 0

Hello I am working with an ajax post function, where I send data and my callback from PHP returns some data back. Based on the data returned I make the decision, either to go forward or allow the user to stay on the page and make changes.

        if (validateStep(step))
        {
        if(step==1)
        { 
            var data = document.getElementById('hiddenContact').value;
            $.post('/app/controller/action', {'data':data}, function(returndata){if(returndata.match('not Unique'))alert('Contact source already exists'); else if(returndata.match('not posted')){alert("Not posted to the database");return false;}});
        }
        step = step + 1;
        form[0].action = '/app/controller/index/step:'+step;
        document.getElementById('step').value = step;
        form[0].submit();
        }

Here I am trying to stop the application going ahead when the return data is matched to “not posted”, and I am throwing an alert and then a return false to stop the operation. I am unable to stop the application from going to next step though. Though it is returned false, the operation continues to the next step, but when I comment the last 4 lines which increment the step, set the action and submit, it stays on the page and the alert is thrown.

Does anybody know what I should do in order halt my process from submission??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:28:38+00:00Added an answer on May 18, 2026 at 4:28 am

    AJAX calls are asynchronous. The “false” you are returning is on the success callback, not on the handler you have shown there. So the last four steps always execute, before the AJAX call even reaches the server. You can fix this by changing ajax response callback to deal with this, like so:

    if (validateStep(step))
    {
        var next_step = function() {
            step = step + 1;
            form[0].action = '/app/controller/index/step:'+step;
            document.getElementById('step').value = step;
            form[0].submit();
        }
    
        if(step==1)
        { 
            var data = document.getElementById('hiddenContact').value;
            $.post('/app/controller/action', { 'data':data }, function(returndata) {
                if (returndata.match('not Unique')) alert('Contact source already exists');
                else if (returndata.match('not posted')) alert("Not posted to the database");
                else next_step();
            });
        }
        else next_step();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i use json_encode to send back data from php to jquery through ajax. and
Currently I am working on a ajax-based web application that does some XHR. I
Hello im working in a generic function that sends an ajax request according with
Hello I am working on getting data from database by sending a piece of
I'm working with PHP 5 here. I have the following code: $data = json_decode($_POST['data']);
Hello (Prevent website url in print from javascript?) I am sure some simple solution
Hello I am a newbie working with jQuery and Ajax. I am trying submit
Hello I am working with a simulator that uses rcS scripts to boot, this
Hello , I am currently working on the student association's website. The student's association
I'm working on a C-brain teaser: Write the standard Hello-World program, without semi-colons. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.