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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:40:26+00:00 2026-05-31T13:40:26+00:00

can someone please tell me why this isn’t working? For some reason I need

  • 0

can someone please tell me why this isn’t working?
For some reason I need more text for this amount of code… cant really see how this could benefit anybody but whatever have some more text…..

This:

if (window.XMLHttpRequest)
   {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
   }
 else
   {// code for IE6, IE5
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
 xmlhttp.onreadystatechange=function()
   {
   if (xmlhttp.readyState==4 && xmlhttp.status==200)

    {
        alert("rS4Xs200");
    var string33 = xmlhttp.responseText;
    //document.write(xmlhttp.responseText);
            return(string33);

    }
  }
  var urlToGet = 'd2/two.php';
  alert(urlToGet);
xmlhttp.open("GET",urlToGet,true);
xmlhttp.send();

}

Returns:

undefined
  • 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-31T13:40:28+00:00Added an answer on May 31, 2026 at 1:40 pm

    The reason it’s showing “undefined” is because the AJAX request is asynchronous and therefore your script calls the AJAXrequestDLC() function and eventually sends the xmlHttpp request, but it then moves on to the write command containing that function call before the onreadystatechange function is fired (because the response hasn’t been returned yet). You can verify this by changing your code to something like:

    function runAJAX2() {
    var result = AJAXrequestDLC();
    alert('boom');
    document.write(result);
    }
    

    You’ll notice that the “boom” alert comes before the alerts in the onreadystatechange function in your code, indicating that the script has moved on while waiting for the response from your PHP file.

    EDIT: Rewritten this answer twice and I still confuse myself a bit so here’s an alternative explanation:

    1. Function runAJAX() is called
    2. document.write(AJAXrequestDLC()); invokes the AJAXrequestDLC() function
    3. Within the AJAXrequestDLC function, the xmlHTTP request is sent
    4. At this point program flow returns to the document.write command, which writes the current value of AJAXrequestDLC() (which is undefined).
    5. At some time microseconds later, the response is returned from the php script and the xmlhttp.onreadystatechange event fires, calling the inline function. However since program flow has already moved on, the return statement has no effect.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please tell me why this isn't working? I would like to be
Please can someone tell me why this isn't working before I defenestrate everything on
Can someone please tell me whats wrong with this code. I'm not getting complete
I can't seem to get this text to align vertically. Can someone please tell
Hi can someone please tell me why this code is incorrect? I'm trying to
Can someone please tell me where I'm going wrong with this piece of code?
Can someone please tell me how I can use this piece of code?. I'm
Can someone please tell me why this is not truncating the text? the last
Can someone please tell me why this code is leaking? Instruments is showing several
Can someone please tell me why this code will not work? It does compile.

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.