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 7536659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:38:10+00:00 2026-05-30T06:38:10+00:00

P.S.: Read EDITED on 2019-06-29: I have a webform for updating user information, and

  • 0

P.S.: Read “EDITED on 2019-06-29”:

I have a webform for updating user information, and when he updates his email a verification is performed via ajax() so that he is warned if the new email address is already in use by another user.

I’m trying to cancel the form submission when the email is in use, but return false; doesn’t work.

Any other return false; within if statements are working fine, the problem is only with this one inside the jQuery.ajax() call.

Here’s the actual code:

var email = jQuery('#email').val();
jQuery.ajax({
    type : 'GET',
    url : '/ajax/verify-email.php?email=' + email,
    success : function( d ) {
        if( d == '1' ) {
            alert('Another user is using this email');
            jQuery('input[name="email"]').focus();
            return false; // this guy over here is not working!!!!
        }
    }
});

Does anyone have a solution?

EDITED on 2019-06-29

When I asked this question back in 2012 I wasn’t aware of Promises in Javascript, neither knew about “$.when” (even though added 3 years later of this question) to handle asynchronous requests alongside $.ajax.

Today, you can handle the same scenario easily, as this:

let email = $('#email').val();
$.when(
  $.ajax({
    type : 'GET',
    url : `/ajax/verify-email.php?email=${email}` 
  })
 .then(function(d) {
   alert('Another user is using this email');
   $('input[name="email"]').focus();
});
// your code continues from here as desired...
  • 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-30T06:38:12+00:00Added an answer on May 30, 2026 at 6:38 am

    The A in AJAX is actually very important. It stands for Asynchronous. This means that you trigger a request to the server which might take some time to process and you get a response later. This response happens inside the success callback. But since this happens much later than the actual form submission, your form has actually been already submitted before the response comes back. So returning false from an AJAX success callback makes no sense whatsoever. What you want to do is to return false from the submit handler of your form. Let’s see how we could implement this.

    You could subscribe to the .submit handler of the form and send an AJAX request to verify whether the email has already been taken or not and if it is not taken manually trigger the submission of the form inside the success AJAX callback:

    $('form').submit(function() {
        // we send an AJAX request to validate the unicity of the email
        $.ajax({
            url: '/ajax/verify-email.php',
            type: 'POST',
            data: { email: $('#email').val() },
            // we set the context to the form so that inside
            // the success callback 'this' points to the form
            context: this,
            success: function(result) {
                if (result != '1') {
                    // If the server send something different than 1
                    // we know that the email is unique and trigger
                    // the submission of the form using the underlying
                    // DOM element to avoid calling the .submit handler
                    // recusrively
                    this.submit();
                } else {
                    // The email is not unique => we are informing
                    // the user that the email is already in use
                    alert('Another user is using this email');
                    $('#email').focus();
                } 
            }
        });
    
        // we cancel the normal submission of the form    
        return false;
    });
    

    Also never rely on client side validation. Make sure that you are performing the email is unique check once the form has been successfully submitted to the server. If you are using a SQL database that’s easily achieved with a unique constraint on your Email field.

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

Sidebar

Related Questions

Read about the issue in this stackoverflow question . Still have the same issue
I have read that after select we use column-names but I have found a
OK I have read many posts regarding Dual Licensing using MIT and GPL licenses.
--- Edited below with some more testing, please read :) --- I'm struggling trying
Is there any way to read Session value through JQuery? Edited: I am calling
I've read that storing login information in cookies is a security risk since they
I have edited this question to make it easier to understand. I have an
I made my entire local workspace read-write then edited a couple of files. When
How to read text from image in android app. Edited: I want to detect
I read that it is bad to have such structure in an iOS application.

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.