View Full Version : XML and Javascript loading problem

04-17-2008, 07:55 PM
Hi, I am building a website for a small business and they want to be able to add pictures to galleries and delete/change. The person that will be doing this has zero programming knowledge so I wanted to make this harmless. I didnt want him going into my html code... Anyways, here is my problem.

I have created an xml file so that to change a picture, you just open it with an editor and change the name of the pictures to the ones that you want to view on that page. My javascript reads this file, loops through it, and creates a dynamic table with the pictures.

This works probably 85% of the time and the other 15%, i get a javascript error and the pictures do not load. But, if i refresh the page, they load just fine... I have 4 pages that uses this script and it usually occurs when I am navigating through my site...

Can someone please help?

04-17-2008, 08:49 PM
You should give more details. First of all if possible your code and a sample XML data. Also in which browsers' which versions do you experinece this problem? What is the error you get? :)

04-18-2008, 01:49 PM
Hi, sorry for the lack of clarity. I have attaced 2 files. tractor.txt is the html file and tractor_pics.txt is the xml file. I am experiencing the problem in firefox, ie6, and ie7.

I would appreciate any help you could give me...

04-18-2008, 06:33 PM
You should be sure that your XML object has created and loaded properly before calling loadMainPics function. This seems to be the source of the problem. Why not using a ready script for AJAX calls which proivdes a cross-browser onload event?

04-18-2008, 09:18 PM
Thank you for the help on this matter.

Why does it create the xml object correctly sometimes and not at all other times? I tried putting it in an onload event, but when I did that my pictures wouldn't get loaded. I didnt get any errors, they just didnt show up.. Weird stuff.

I tried putting the code that creates the xml object in a function and then if succeeded go to loadMainPics but, like I said, pics didnt show up..

04-19-2008, 07:47 AM
You know, browsers do cache things. Probably you do not get an error when it very quickly loads from cache but you get an error when it really tries to fetch the data from server. I suggest you to use XMLHTTPRequest object which has an "onReadyStateChange" event ;)