Reputation: 32143
I'm developing a very smooth site that will display products for a company. I'm using jQuery to display the products. Problem is, I don't want to hard-code all of the products in. I want to store all of the products (product, description, price, etc.) in XML. I'm not worried about security because clients wont actually be buying anything directly from site.
With this in mind, what is the best way to load and read the XML file using Javascript/jQuery. I've read some stuff online but it all looks pretty dodgy, especially when it comes to browser support. Is this realistically possible? Should I do this another way? How can I best achieve this?
EDIT
JSON also seems like a decent alternative as well. I just need explanations on how to do it.
Thanks!
Upvotes: 0
Views: 98
Reputation: 7279
I agree that it should be easier to use JSON if you are using JavaScript directly.
If you want to use XML, you might be interested in using XQuery or XSLT (which natively support XML, and almost seamlessly (X)HTML) as the scripting language.
Upvotes: 2
Reputation: 16129
Storing data as JSON is a cleaner bet and it works a lot more seamlessly with JavaScript.
JQuery's ajax functions have a built in JSON data type that automatically parses if for you.
I would look into JSON at json.org and then start looking at some of the JQuery docs. It's not too complicated.
Really it's just JavaScript objects in string format. You deal with them, after parsing, as normal objects.
Upvotes: 4