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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:24:09+00:00 2026-05-25T19:24:09+00:00

function check_username(){ $.ajax({ type: POST, dataType: ‘json’, url: /ajax/check/username.html, data: via=ajax&username=+$(‘input[name=register_username]’).val(), success: function(msg){ if(msg.response==false){

  • 0
function check_username(){
    $.ajax({
        type: "POST",
        dataType: 'json',
        url: "/ajax/check/username.html",
        data: "via=ajax&username="+$('input[name=register_username]').val(),
        success: function(msg){
            if(msg.response==false){
                register_username.parent().css('background-color','#db2e24');
                register_username.parent().parent().find('td:last-child').text(msg.message);
                register_username.focus();
                return false;
            } else {
                register_username.parent().css('background-color','#fff');
                register_username.parent().parent().find('td:last-child').text("");
                return true;
            }
       }
    });
}

I’m sorry if my English isn’t good — English is not my native language.
Back to the topic, why does the function above always return false?
FYI : the JSON is OK

  • 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-25T19:24:10+00:00Added an answer on May 25, 2026 at 7:24 pm

    check_username calls an ajax function which starts a networking operation and then returns immediately. check_username returns long before the ajax call finishes and the success handler gets called. Thus, the success handler has NOTHING to do with the value that check_username returns.

    Since there is no return value in the check_username function itself (only in the embedded success handler function), check_username returns undefined which is a falsey value, thus you think it’s always returning false.

    If you want to do something with the return value from the success handler, then you have to either operate in the success handler itself or you have to call another function from the success handler. This is how asynchronous operations work.

    Returning true or false from the success handler function does nothing. The success handler is called by the internals of the ajax handling code and returning from the success handler just goes into the bowels of the ajax internals. The return value from the success handler is not used in any way.

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

Sidebar

Related Questions

I have written this ajax request for username checking... function check_username() { var username
I'm using this Jquery function for available username check. How can I fire this
function check(id){ var _id = document.getElementById(id); url = test.php?check=1&id= + _id; } i want
I have a JSON request that check to the server if a username has
I'm trying to do a ajax check of username availability and submitting a form
I created a callback function to check if the username exists in the DB.
<button type=button value=click me onclick=check_me(); /> function check_me() { //event.preventDefault(); var hello = document.myForm.username.value;
As you can see I am retrieving JSON data from my ajax call but
$(document).ready(function() { //Check City Value var city_value = parseInt($(#city).val()); if( city_value == 0) {
I have used Javascript onlaod like this: function check() { var pic = new

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.