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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:43:43+00:00 2026-06-02T10:43:43+00:00

I am trying to retrieve an xml file from the server via ajax, but

  • 0

I am trying to retrieve an xml file from the server via ajax, but cannot get it to parse. I do not know what I am doing wrong. When I call the getFriends.php, it prints the xml fine. here is the ajax code:

<!DOCTYPE>
<html>
<head>
<title>Ajax Sample</title>

<script type="text/javascript">

function getFriendsList(MemberId) {

    var xmlhttp;

    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) {

            var xmlDoc = xmlhttp.responseXML;
            var friendElements = xmlDoc.getElementsByTagName('friend');

            for (var x=0; x<friendElements.length; x++) {
                // We know that the first child of show is title, and the second is rating
                var id = showElements[x].childNodes[0].value;
                var name = showElements[x].childNodes[1].value;

                // Now do whatever you want with the show title and ratings
                document.write("hi");
          }

        }
    }

    xmlhttp.open("POST","getFriends.php",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send("id=" + MemberId);

}

</script>

</head>

<body>

    <input name="ajax" type="button" onClick="getFriendsList(1)" value="Click for AJAX">
    <div style="background-color:#00FF99;" id="placehere">Here is where the update will occur.</div>
</body>
</html>

and here is the getFriends.php code (user class works fine):

<?php
include('lib.php');
//$id = $_POST['id'];
$id=1;
$user = new User($id);

echo $user->getFriendsList();

?>
  • 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-02T10:43:45+00:00Added an answer on June 2, 2026 at 10:43 am

    You have undefined variable ‘showElements’ in your for loop. These two lines:

    var id = showElements[x].childNodes[0].value;
    var name = showElements[x].childNodes[1].value;
    

    should be replaced with:

    var id = friendElements[x].childNodes[0].value;
    var name = friendElements[x].childNodes[1].value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam trying to retrieve data from mysql database into stylesheet.php but it is not
I'm trying to retrieve a file from a server using SFTP (as opposed to
I am using liferay technology and trying to retrieve data from xml file in
I am trying to retrieve content from xml tagnames from a url, but my
I'm trying to retrieve information from an online XML file and it takes too
I am trying to retrieve from an xml file which holds list of the
I'm trying to retrieve N number of items from an XML file using simpleXML
I'm trying to retrieve an XML stream from a URL. For most URLs my
I'm trying to use e4x to retrieve xml from the result event thrown when
From the XML below I'm trying to retrieve the second element in the sequence.

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.