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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:43:26+00:00 2026-05-15T00:43:26+00:00

this is a part of the check in my form function check(theform) { var

  • 0

this is a part of the check in my form

function check(theform) {
var re = /^\w[0-9A-Za-z]{5,19}$/;
if (!re.test(theform.username.value)) { 
    alert("not valid username");
    theform.username.focus();
    return false;
}

$.ajax({
    type: "POST",
    url: "username.asp",
    data: "username="+theform.username.value,
    success: function(msg){
        username = msg;
        if (!username) {
            alert("username already in use");
            return false;
        }
    }
});

var re = /^\w[0-9A-Za-z]{5,19}$/;
if (!re.test(theform.password.value)) { 
    alert("not valid password");
    theform.password.focus();
    return false;
}
}

for some reason of sync… it check the username then duplicated username with the ajax and not waiting for respond and jump to the password check.

i don’t want to insert the rest of the code to isreadystate (or what ever it is) because i might move the username duplicate check to the end… and then the function will end before the ajax anyway

what should i do?

  • 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-15T00:43:27+00:00Added an answer on May 15, 2026 at 12:43 am

    The first A in AJAX stands for “Asynchonous”. The call is made, and the execution of the function continued without waiting for the call to return.

    You could set the async option in your call to false, making your call sychronous. However, you would have to change your functions so the return false makes it through to the check function, and it is not recommended by the jQuery manual:

    The first letter in Ajax stands for “asynchronous,” meaning that the operation occurs in parallel and the order of completion is not guaranteed. The async option to $.ajax() defaults to true, indicating that code execution can continue after the request is made. Setting this option to false (and thus making the call no longer asynchronous) is strongly discouraged, as it can cause the browser to become unresponsive.

    a better way around it would be to make the checks you can make in “real time” within the function, then start the Ajax request, and submit the form in the success callback of that request.


    2nd attempt at a syncrhonous call. This seems to actually work – tested in FF 3.6.

    var name_success = true;
    
    $.ajax({
        type: "POST",
        async: false,
        url: "username.asp",  // Needs to return "EXISTS" in this example 
        data: "username="+theform.username.value,
        success: function(msg){
            username = msg;
            if (username == "EXISTS") {  // Changed callback return value - 
                                         // safer this way
                alert("username already in use");
                name_success = false;   // should work because
                                        // we're in check()'s scope
                return false;
            }
        }
    });
    
    alert (name_success);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This does not work <h:form style=display: inline;> <h:outputLink value=#{title.link} > #{msg['g.readMore']} <f:ajax event=click immediate=true
I have this part of the function : $jQ('.product-collateral .product-tabs li').each(function(index){ $jQ(this).attr('id', $jQ(this).find('h3').attr('class')); if(index
I have this part of code in my functions.php: function cc_admin_enqueue_scripts($hook) { $file_dir=get_bloginfo('template_directory'); wp_enqueue_script('media-upload');
Jquery: <script type=text/javascript> $(document).ready(function(){ $(form.register).change(function() { $.post(check.php, $(form.register).serialize(), function( data ) { if( data.username
This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =
This part of my code is used to award a grade to a student
This part of an app that I am working on, I have the following
It seems that this part of my code is where the exception occurs: c
For some reasons this part where I fetch JSON data from following url will
You may skip this part: I am creating an application where the client needs

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.