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

  • Home
  • SEARCH
  • 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 6144415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:38:50+00:00 2026-05-23T18:38:50+00:00

For some reason I always receive undefined if I return the value but if

  • 0

For some reason I always receive undefined if I return the value but if I’m trying to display it in alert I receive the php values.


function getXMLHttp() {
  var xmlHttp

  try {
    //Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  } catch(e) {
    //Internet Explorer
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        //Browser does not support AJAX
        return false;
      }
    }
  }

  return xmlHttp;
}

function isUsernameExists() {
  var xmlHttp = getXMLHttp();

  xmlHttp.onreadystatechange = function() {
    if (xmlHttp.readyState == 4) {
    handleResponse(xmlHttp.responseText);
    }
  }

  var str = document.getElementById('username').value.toString();
  xmlHttp.open("GET", "ajax.php?username="+str, true);
  xmlHttp.send(null);

}

Edit:


function handleResponse(response) {
    return response.toString();
}

Thanks,

Guy Dor

  • 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-23T18:38:51+00:00Added an answer on May 23, 2026 at 6:38 pm

    It looks like you are trying to read the return value from this function:

    function isUsernameExists() {
    

    It doesn’t have a return statement, so it will always be undefined.

    I’m guessing you expect this return statement to pass the value you want:

    return xmlHttp.responseText.toString();
    

    But that is part of this function:

    xmlHttp.onreadystatechange = function() {
    

    Which is called automatically when the readystatechange event fires, and not by any function call you make.

    Asynchronous JavaScript and XML rarely uses XML but is asynchronous. Anything you want to do with the data fetched needs to be done by the callback function you assign to onreadystatechange. It can call other functions, but it cannot return anything (at least not that will be received anywhere useful).

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

Sidebar

Related Questions

I am trying to iterate on my database records. but for some reason it
For some reason I have always assumed that most of the time a variable
For some reason I've always had trouble remembering the backwards/forwards compatibility guarantees made by
For some reason, my form is always at 100% opacity. I've tried changing it
For some reason, Section 1 works but Section 2 does not. When run in
So i'm trying to write out an object to a ByteArray, but for some
My ImageView for some odd reason is always displaying a picture in the middle,
I just trying to get the anchor text of a link. $('a').click(function(){ alerT($(this).val()); });
I'm sending mails from my rails application but for some reason I never get
Hey im writing an echo client, and for some reason the connectsock function is

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.