Basic AJAX: hasChildNodes() method

Hi Experts,

Please help me as I study ajax.
I encounter the error message:
“hasChildNodes() is not a method”

Here is my source code:

var xmlName = ‘products.xml’;
var xmlDoc;
if (window.XMLHttpRequest)
xmlDoc=new window.XMLHttpRequest();“GET”,xmlName,false);
xmlDoc=new ActiveXObject(“Microsoft.XMLDOM”);

//error method here
var xmlcode = new Array(xmlDoc.getElementsByTagName(“product”).lengt h);

Here is the products.xml:


Please help me why I encounter this error message?

Thank you very much,

Does it behave any better when the XML file starts with an XML doctype?

I also see at some code that might provide better results for you when loading an XML document.

What if you use this?

if (xmlDoc.documentElement && xmlDoc.documentElement.hasChildNodes()) {