This week's giveaways are in the MongoDB and Jobs Discussion forums. We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line! See this thread and this one for details.
I have a small hitch in reading the contents of an XML file.. the following code reads the contents properly. But the contents are refreshed dynamically and everytime it gets refreshed the loading in javascript doesnt get resfreshed. It take some time.
xmlDoc.load("xmls/messageXML.xml"); var doc=xmlDoc.documentElement; if(doc!=null) { alert(doc.childNodes[0].childNodes[0].text); } [ August 14, 2006: Message edited by: Bear Bibeault ]
Liu Zhixiang
Ranch Hand
Joined: Aug 12, 2006
Posts: 32
posted
0
function abcd() { var xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.load("1.xml"); var doc=xmlDoc.documentElement; if(doc!=null) { alert(doc.childNodes[0].childNodes[0].text); } } setInterval("abcd()",5000); [ August 14, 2006: Message edited by: Liu Zhixiang ]
I Think Therefore I Am
Ayyappan Selvaraj
Ranch Hand
Joined: Sep 20, 2004
Posts: 63
posted
0
yes i tried this with 2000(2 secs) but its taking 2 second which is costly.
And moreover when the content of the XMl changes why the XMl loding doesnt take place in javascript?
Liu Zhixiang
Ranch Hand
Joined: Aug 12, 2006
Posts: 32
posted
0
Because the xmlDoc.load() is a method to get the XML's current value ,which isnt a import [ August 14, 2006: Message edited by: snowwolf ]
Eric Pascarello,3Q "+Date()" appended to the request URL will be safer. I mistake the meaning of TOP Sorry
Ayyappan Selvaraj
Ranch Hand
Joined: Sep 20, 2004
Posts: 63
posted
0
Thank you very much for all your replies. But my problem is no caching of data due to resuests in Ajax but XML reading object...
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.load("xmls/messageXML.xml"); var doc=xmlDoc.documentElement; alert(doc.childNodes[0].childNodes[0].text);
Im getting the cache problem with this XMl loading object... So a code to clear the chache of this object is reuired
thanks in advance
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
6
posted
0
It is the same thing here....
append the date to the name of the XML document.
Eric
Ayyappan Selvaraj
Ranch Hand
Joined: Sep 20, 2004
Posts: 63
posted
0
yes thanks for the ideas that you gave.. its working now...
And one more thing I want to know, before using the XML system file method in Ajax, I used to write XML content to the response object in the Java coding and read it in the Javascript. But when reading response object as
var responseXML = req.responseXML; var details = responseXML.getElementsByTagName("details")[0];
I got null object at the second line...
So do you have any idea what would be the error there and can you suggest me which one is the best method to get data ufing Ajax... through response object or file system...and why?
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
6
posted
0
this line should read var responseXML = req.responseXML.documentElement;
If the getElementsByTagName does not work, than that means the XML document coming back is not structured correctly. Open up the document directly into the browser and see if it gives error messages.