Page 1 of 1

[SOLVED] Problem reading XML with AJAX in IE.

Posted: Sun Jan 31, 2010 2:09 pm
by granite
Hello there! :)

I'm with a problem in my ajax code when using IE8. In Firefox everything works perfectly though.
What I'm trying to do is retreiving data from a XML that's generated based on data from the database.
Here's the error the browser returns:
Use Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; AskTB5.3)
Date/hour stamp: Sun, 31 Jan 2010 19:32:41 UTC

Message: The Object doesn't support the property or method
Line: 121
Character: 2
Code: 0
Now, to the AJAX code (where line 3 is line 121, referenced in the error above):

Code: Select all

function aplicaBanners(obj,divTop,divLat){
    dataArray = obj.getElementsByTagName("banners");
    topo = dataArray[0].getElementsByTagName("topo"); 
    lateral = dataArray[0].getElementsByTagName("lateral");
    if(topo && topo.length>0){
        bannerT = topo[0];
        tituloT = bannerT.getElementsByTagName("titulo")[0].firstChild.nodeValue;
        linkT = bannerT.getElementsByTagName("link")[0].firstChild.nodeValue;
        imagemT = bannerT.getElementsByTagName("arquivo")[0].firstChild.nodeValue;
        imgextT = imagemT.substring(imagemT.lastIndexOf('.')+1);
        if(imgextT=="swf" || imgextT=="SWF") 
            htmlT = "<a href=\"http://"+linkT+"/\"><embed src=\"admin/"+imagemT+"\" title=\""+tituloT+"\" /></a>";
        else 
            htmlT = "<a href=\"http://"+linkT+"/\"><img src=\"admin/"+imagemT+"\" title=\""+tituloT+"\" /></a>";
        divTop.innerHTML = htmlT;
    }
    if(lateral && lateral.length>0){
        htmlL = "";
        for(i=0;i<lateral.length;i++){
            bannerL = lateral[i];
            tituloL = bannerL.getElementsByTagName("titulo")[0].firstChild.nodeValue;
            linkL = bannerL.getElementsByTagName("link")[0].firstChild.nodeValue;
            imagemL = bannerL.getElementsByTagName("arquivo")[0].firstChild.nodeValue;
            htmlL += "<div><a href=\"http://"+linkL+"/\"><img src=\"admin/"+imagemL+"\" title=\""+tituloL+"\"/></a></div>";
        }
        divLat.innerHTML = htmlL;
    }
}
And here goes the generated XML:

Code: Select all

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<banners>
<topo>
<titulo>Banner de teste</titulo> 
<link>http://www.teste.com</link> 
<arquivo>banners/12647915244b632fe4df78b.jpg</arquivo> 
</topo>
<lateral>
<titulo>Banner Lateral 1</titulo> 
<link>http://www.bannerlaterialone.com</link> 
<arquivo>banners/12648245294b63b0d19e3b5.jpg</arquivo> 
</lateral>
<lateral>
<titulo>Banner Lateral 2</titulo> 
<link>http://www.bannerlaterialtwo.com</link> 
<arquivo>banners/12648261174b63b705bc6f1.jpg</arquivo> 
</lateral>
</banners>
So, this is it. Does anyone have any idea of why this is not working?

Thanks in advance,

Hênio.

Re: [SOLVED] Problem reading XML with AJAX in IE.

Posted: Tue Feb 02, 2010 12:11 pm
by granite
Don't know why, but the problem here was the name of the variable "topo". I just renamed it to "topoB", and then everything was ok. :banghead:
Is "topo" a reserved word in Internet Explorer? Some time ago I had the same problem with a variable named "link". WTH...