jQuery: Query an Xml document and output data
I back-dated my first piece of jQuery code, but have decided not to with my second.
Anyways, I had a hard time finding code, written in jQuery, to pull data from an Xml file and add it to a page. Combining a couple of tutorials online, I created the following (on April 27).
This was for a message, so I started out with the Xml file, creating something like this:
<?xml version="1.0" encoding="utf-8"?> <messages> <system><![CDATA[Test system message.]]></system> </messages>
I wanted multiple messages to be able to be stored, hence the format.
Next I had to create the code to pull in the message that I wanted.
This is where it got tricky, since I couldn't find code that did this, just a number of individual pieces of it. Putting it all together, it worked as I wanted.
We needed to refresh the content as well, and with the help of a plug-in, we were able to make this data call when we wanted (on a timer) and refresh the contents of the div as appropriate.
Support This Site
If my blog was helpful to you, then please consider visiting my Amazon Wishlist.