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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:57:25+00:00 2026-05-22T00:57:25+00:00

I understand that AJAX is asynchronous, and all that. But I have the following

  • 0

I understand that AJAX is asynchronous, and all that. But I have the following code:

function doesUsernameExist(element)
{
    // Check via AJAX (POST) if username already exists in the database
    var funcReturned = null;
    $.post(
        '_ajax_checkexist.php',
        {
            var: 'username',
            value: element.value
        },
        function(data) {
            funcReturned = (data.toLowerCase() == 'exists');
        },
        'data'
    );
    return funcReturned;
}

I understand why the function isn’t returning a value properly, but what can I use as a workaround? This is for the Validity plugin, which requires a boolean returned by the doesUsernameExist function. I can’t do the usual workaround of having the $.post function alter some HTML element. It needs to return true/false to doesUsernameExist.

What kind of workaround can I use? I’m stumped by this.

  • 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-22T00:57:26+00:00Added an answer on May 22, 2026 at 12:57 am

    If this is for validation purposes you will find that the jquery.validate plugin and its remote rule are perfectly adapted for what you are trying to achieve.

    So, instead of writing doesUsernameExist functions and worrying about asynchronousness of AJAX and how to return values you will write validation rules for your form (which in fact is the final goal of the exercise => focus on the business and leave the plumbing to plugins):

    $('#id_of_some_form').validate({
        rules: {
            password: {
                required: true
            },
            username: { 
                remote: '_ajax_checkexist.php'
            }
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that Javascript doesn't have multiple threads, but I'd like to know if
I have simple JavaScript code that is using the Ajax API for fetching a
I understand that you are not allowed to make cross domain Ajax calls, but
I have an issue using Ajax upload with Spring 3 MVC. I understand that
I understand that we can set the various style attributes from code behind using
I understand that in CUDA's memory hierachy, we have things like shared memory, texture
You'll have to forgive me on this one. I understand that the issue is
So I just finished writing my first Ajax function. I did it all from
I understand that I could show online users using ajax. For example, I could
I understand that the maximum length for an AJAX call using GET is 2083

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.