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

  • Home
  • SEARCH
  • 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 4617954
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:11:51+00:00 2026-05-22T02:11:51+00:00

i am trying to return value from ajax request to a function on form

  • 0

i am trying to return value from ajax request to a function on form submit.

The code is as below:

function validateEmail(){ 
        if(email.val() == "")
        {
            $("#emailerror").html("Enter Email...");
            return false;
        }
        else {
        $.ajax({
            type: "POST",
            data: "email="+email.val(),
            url:'emailcheck.php',
            beforeSend: function(){
                $("#emailerror").html("Checking Email...");
            },
            success: function(data){
                if(data == "invalid")
                {
                    $("#emailerror").html("Invalid Email");
                    return false;
                }
                else if(data != "0")
                {
                    $("#emailerror").html("Email Already Exist");
                    return false;
                }
                else
                {
                    $("#emailerror").html("OK");
                    return true;
                }
            }
        });
        }
    }

On form submit, i am calling the function and checking the return value from ajax response:

$('#myForm').submit(function(){
        if(validateEmail())
        {
            alert('returning true');
            return true;
        }
        else
        {
            return false;
        }
});

But, the code is not executed when the return value is ‘true’. The function validateEmail() return false.

Pls help me to figure out where i went wrong..

Thanks in advance.

  • 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-22T02:11:52+00:00Added an answer on May 22, 2026 at 2:11 am

    The “A” in AJAX stands for “asynchronous”.

    In the else branch of validateEmail, you’re launching an asynchronous request to emailcheck.php. validateEmail will return before your PHP file responds; then your emailcheck.php script does respond, jQuery will call your success callback but no one will pay attention to what it returns. The result as far as form validation is concerned, is that your validateEmail looks like this:

    function validateEmail() { 
        if(email.val() == "") {
            $("#emailerror").html("Enter Email...");
            return false;
        }
        else {
            // Your $.ajax() might as well not even be here as
            // validateEmail will return before $.ajax() gets a
            // response from emailcheck.php
            return;
        }
    }
    

    You could try the async:false option for $.ajax or rework all your logic to be able to wait for the asynchronous request to return.

    Furthermore, the second branch of validateEmail does not return false, it doesn’t return anything at all but that’s still not a true value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to return the value that a $ajax call returns, from a function
I'm trying to return a value from (transport) to the calling function, but can't
I've been trying to return special characters from an AJAX request to a PHP
im trying to return a string value from a method inside my script tag
I'm trying to return a dictionary from a function. I believe the function is
I am trying to use Linq2Sql to return all rows that contain values from
I'm trying to find a way to return the value of an array's parent
I'm trying to return a reference to an object, not pass it by value.
Am trying to pass the selected check box value to the control function. Please
Here's what I'm trying to do. When the 'Submit' form is clicked on 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.