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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:07:40+00:00 2026-06-11T13:07:40+00:00

I’m working on adding some Ajax to a web page that I have using

  • 0

I’m working on adding some Ajax to a web page that I have using jQuery. Note that I’m new to Ajax. The page is a simple registration form, and I want to check if the email address the user supplies is already registered, and tell the user if it is, before the form redirects to registration code.

I’ve been reading this question and its answers, and experimenting to reproduce the effect, but without success.

When I click on submit, the javascript function is called (I’ve proven this by adding some diagnostic code into the checkEmail() function), however when I check my Apache server logs, I can see all the requests that I’m expecting, except for the call to /user/process/chechemail.php. The code (below) is located in the /user/ directory, I’ve modified the url: path with all variations of relative and absolute paths. Nothing is recorded in the Apache error log.

When the user clicks the submit button, they see the message “Something went wrong!”. Can anyone spot what is wrong?

The code I have is as follows:

<script>
    function checkEmail()
    {
        $.ajax(
        {
            type: "POST",
            dataType: "html",
            data:
            {
                email: $('#email').val()
            },
            url: "/user/process/checkemail.php"
        })
        .done(function(response)
        {
            $('#message').html(response);
        })
        .fail(function()
        {
            $('#message').html("Something went wrong!");
            return false;
        });
    }
</script>

<div id="register-form">
    <form name="register" action="process/register.php" method="post" onsubmit="return checkEmail();">
        <div class="register-email-cell">
            <p class="text">Email Address</p>
        </div>
        <div class="register-email-cell">
            <input class="input" type="text" name="email">
        </div>
        <div class="register-email-cell">
            <input class="button" type="submit" value="Register">
        </div>
        <div>
            <p id="message" class="text"></p>
        </div>
    </form>
</div>

Notes:

  • The <script> reference to jQuery is in a PHP include, not shown above
  • /user/process/checkemail.php – looks for $_REQUEST[’email’], and performs a query against the database and returns a string stating either ‘Email address exists’ or ‘Email address available’ – I realise that this might allow bots to harvest email addresses, but this is just sample code used for my own learning. – It isn’t going to be production code.
  • 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-06-11T13:07:41+00:00Added an answer on June 11, 2026 at 1:07 pm

    Your checkEmail() function returns undefined immediately, which does not prevent the form from submitting. Your page gets reloaded before the AJAX request has the chance to even start. AJAX requests are asynchronous — they run in the background, and their callbacks are executed outside of the control flow surrounding the actual call to $.ajax(), and the callbacks’ return values are discarded.

    One way to accomplish what you’re trying to do, is to have the done callback set a flag if the check is successful and submit the form again, and have the checkEmail() function return false if the flag is not set:

    var emailChecked = false;
    function checkEmail()
    {
        if (emailChecked) {
            return true;
        }
        $.ajax(
        {
            type: "POST",
            dataType: "html",
            data:
            {
                email: $('#email').val()
            },
            url: "/user/process/checkemail.php"
        })
        .done(function(response)
        {
            $('#message').html(response);
            emailChecked = true;
            $('form[name=register]').submit();
        })
        .fail(function()
        {
            $('#message').html("Something went wrong!");
        });
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I'm making a simple page using Google Maps API 3. My first. One marker
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.