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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:37:25+00:00 2026-06-08T03:37:25+00:00

I’ve an ajax registration form. The user may type in the desired username in

  • 0

I’ve an ajax registration form. The user may type in the desired username in the input field and then immediately hit the register button, while the ajax request to check if the username is available or not wasn’t completed. For this case I want the actions of the register button to start executing only if the ajax request to check username is complete, otherwise wait for it to complete and then proceed. How to do this?

I want the username validation function to remain asynchronous because it executes every time the user does a key-up on the input field.

One way is to enter into a setTimeout() loop when the register button is clicked, and to stay in it until the flag is good. Another way is to call a synch username check request if the asynch request isn’t complete. Is there a better method?

It’ll be nice if you give answer without using jQuery.

  • 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-08T03:37:26+00:00Added an answer on June 8, 2026 at 3:37 am

    Don’t use setTimeout for this.

    Simply use the callback capabilities of jquery’s ajax : execute your “after” code in the success callback or the new done helper :

    $.ajax({
      url: "test.html"
    }).done(function() { 
      // do things after the answer has been received
    });
    

    EDIT :

    Without jquery, and without immediate triggering :

    var httpRequest = new XMLHttpRequest();
    var requestDoneAndOK = false;
    httpRequest.onreadystatechange = function() {
        if (httpRequest.readyState === 4) {
            if (httpRequest.status === 200) {
                    requestDoneAndOK = true;
            }               
        }
    };
    httpRequest.open('GET', url);
    httpRequest.send();
    

    And when the “register” button is clicked, you just have to check requestDoneAndOK and if it’s true call your other function.

    EDIT 2 :

    Code is executed as soon as 2 conditions are realized : answer received and register button clicked.

    var registerClicked = false;
    var ajaxAnswerReceived = false;
    function check() {
        if (registerClicked && ajaxAnswerReceived) {
             // do the thing !
        }
    }
    var httpRequest = new XMLHttpRequest();
    var requestDoneAndOK = false;
    httpRequest.onreadystatechange = function() {
        if (httpRequest.readyState === 4) {
            if (httpRequest.status === 200) {
                  ajaxAnswerReceived = true;
                    check();
            }               
        }
    };
    httpRequest.open('GET', url);
    httpRequest.send();
    document.getElementById('registerButton').onclick = function(){
         registerClicked = true;
         check();
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.