I hav read so many articles on how to access the key values of an xml array but none is helping me.
Here is my issue,
I have a JavaScript code that keeps checking if there is an active timer session in the db after every second. There is a session.php script that fetches the active sessions and returns an array id's of active rows.
This is the array that is returned by session.php
Array ( [0] => response77011 [1] => response110022 )
I converted this array to xml array using the following code (this code is in session.php)
$array = $responses; ($response is an array from a db fetched using php)
//This function create a xml object with element document.
$arr = array_flip($array);
$xml = new SimpleXMLElement('<document/>');
array_walk_recursive($arr, array ($xml,'addChild'));
print $xml->asXML();
on my index.php page, i have the following code
setInterval(function() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","session.php",false);
xmlhttp.send(null);
y = xmlhttp.responseText;
console.log(y);
//var parser = new DOMParser();
// var xmlDoc = parser.parseFromString(y.responseText, "text/xml");
//If the array contains multiple ids,I need to loop them to show in the id attribute ot the 'td' of my //table
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","response.php",false);
xmlhttp.send(null);
document.getElementById(y).innerHTML=xmlhttp.responseText;
console.log(xmlhttp.responseText);
}, 1000);
The above code gives the following output on the console
<?xml version="1.0"?>
<document><0>response77011</0><1>response110022</1></document>
( the above is console.log(y): where y is an array from session.php )
I want to loop through the array so that i get the value 'response77011' or 'response110022' and any other value in the array.
in each loop, I would like to display it in an id on a 'td' table element.
how can I achieve this please, it has really gnawed on me.
yis not an element ID, it's the complete XML, why do you usedocument.getElememtById(y)?