Jump to content

Loading xml file


Jay@TastefulTitles.com
 Share

Recommended Posts

I have been using the following function to load my xml data file. It used to be solid, but now it often (but not always) fails to load and goes on to create errors in the next function when it tries to use the data. I don't know whether that's because the data file is growing larger, or if that's unrelated, but I need something I can depend on.

I've experimented with some other load functions found online, but have had no more success with them. I'm using the synchronous version, as I understand it is supposed to wait until the load is done before going on. Is  my understanding flawed? Is there an asynchronous version with callback that would be more reliable?

//--------------------------------
function getTitlesList() {
 if (window.XMLHttpRequest) {
  var xhttp = new XMLHttpRequest();
 }
 xhttp.open("GET", "/Titles data.xml", false);
 xhttp.send();
 var Works = xhttp.responseXML;
 return Works.getElementsByTagName("work");
}
//--------------------------------

 

Link to comment
Share on other sites

Synchronous requests are deprecated since they cause the browser to freeze, many browsers don't support them anymore.

You have to give your request an onreadystatechange handler and put your code in there.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...