/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] XML DOM working in IE but not FireFox

Hello,

I am trying to read from an XML file i use for RSS… I got it to work with AJax and XML DOM in IE but for some reason it wont work in firefox or safari on my mac(dont know if it being on my mac matters).

here is the code I used for XML DOM

[code=php]
<script type=”text/javascript” language=”javascript”>
var xmlDoc;
if (window.ActiveXObject) {
xmlDoc=new ActiveXObject(“Microsoft.XMLDOM”);
xmlDoc.async=false;
xmlDoc.load(“NewsFeed.xml”);

var x = xmlDoc.getElementsByTagName(‘pubdate’);
var y = xmlDoc.getElementsByTagName(‘description’);

var a = 0;

for (i=1;i<= x.length;i++) {

document.write(x[a].childNodes[0].nodeValue);
document.write(” – “);
document.write(y[i].childNodes[0].nodeValue);
document.write(“<br /><br />”);
a++;
}
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument) {
xmlDoc=document.implementation.createDocument(“”,””,null);
xmlDoc.load(“NewsFeed.xml”);
document.write(“you are using FireFox”);
document.write(xmlDoc.getElementsByTagName(“pubdate”)[0].childNodes[0].nodeValue);
} else {
alert(‘Your browser cannot handle this script’);
}
</script>

[/code]

and like i said it worked in IE.

here is the AJAX Im trying

[code=php]
<script type=”text/javascript” language=”javascript”>
var XMLHttpRequestObject = false;

if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new ActiveXObject(“Microsoft.XMLHTTP”);
}

if(XMLHttpRequestObject) {
XMLHttpRequestObject.open(“GET”, “NewsFeed.xml”, true);
var xmlDocument = XMLHttpRequestObject.responseXML;

var x = xmlDocument.getElementsByTagName(“pubdate”);

listPubDate(x);
/*document.write(“Object Created”);*/
}

function listPubDate(x) {
document.write(“got the publications dates dates”);
}
</script>
[/code]

And even though I have a script for both browsers the information still won’t show up in firefox or safari. However if i un-comment document.write(“Object Created”); and comment out the 4 lines above it… mozilla and safari will display that the object was created..

I ran firefox’s javascript console to debug for the hell of it and it said there was a syntax error.. but I can’t seem to find it and I know that that debugging method isn’t always the best… If you can help I would greatly appreciate it.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterOct 18.2006 — IE is making an Sjax request and doesn't need the onreadystatechange event handler because of the added line xmlDoc.async=false;

However Firefox is making an Ajax request because you failed to add xmlDoc.async=false; for Firefox and therefore it expects an onreadystatechange event handler.
Copy linkTweet thisAlerts:
@blckspderauthorOct 18.2006 — Ahh thanks let me try that!
Copy linkTweet thisAlerts:
@blckspderauthorOct 18.2006 — I got it to display in firefox... Thanks

here is the final code Im using

[code=php]
<script type="text/javascript" language="javascript">
var xmlDoc;
if (window.ActiveXObject) {
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("NewsFeed.xml");

var x = xmlDoc.getElementsByTagName('pubdate');
var y = xmlDoc.getElementsByTagName('description');
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument) {
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.async=false;
xmlDoc.load("NewsFeed.xml");

} else {
alert('Your browser cannot handle this script');
}

var x = xmlDoc.getElementsByTagName('pubdate');
var y = xmlDoc.getElementsByTagName('description');

var a = 1;

for (var i=0;i<=x.length;i++) {
document.write(x[i].childNodes[0].nodeValue);
document.write(" - ");
document.write(y[a].childNodes[0].nodeValue);
document.write("<br />");
a++;
}
</script>

[/code]
×

Success!

Help @blckspder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...