The JavaScript function is:
function loadData()
{
const xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
if (xhttp.readyState == 4 && xhttp.status == 200)
{
const data = xhttp.responseXML.documentElement.getElementsByTagName("ELEMENT");
const text = data + data.length;
document.getElementById("content").innerHTML = text;
}
}
xhttp.open("GET", "ajax/data.xml", true);
xhttp.send();
}
The response (viewed in the browser console) shows:
<?xml version="1.0" encoding="UTF-8"?>
<ELEMENT>
<ID>0</ID>
</ELEMENT>
I expected the output to be something like "[0], 1" (indicating a list with one element and its length), but it actually prints "[object NodeList] 0", indicating that it doesn't recognize any "ELEMENT" elements. What could be causing this issue? Thank you.