XML ajax / javascript / jquery
What would be the best wa开发者_JAVA百科y to write some values into a xml file? In the .html file i have a certain score that gets its values from a js file called jsfuncions.js
Tried looking on several sites for this but never found a clear and simple answer.
Do i have to place the writer into my index file with script tags directly?
Also do i have to use the var xml = new xmlwriter(); Or is there something more simple in jquery to fit this purpose?
Pretty sure i have to use var XML = new XMLWriter();
But there is simply nothing to be found about this funcion. Can anyone point me in the right direction for a simple writer?
Regards.
JavaScript can not update the XML file permanently. You will need to use a serverside language to make the changes permanent.
Browser security sandboxing will prevent a web page being able generate a file and save it locally.
The only local persistence you can use is cookies - you could look at JSON format for storing records with properties and values inside a cookie - limitations are the max size allowed of the cookie.
There's a new local storage mechanism arriving with HTML5 which some of the latest browsers support.
http://people.w3.org/mike/localstorage.html
It really depends what you want to do with the resulting XML. If you want to save information entered by users, then you'll need to use a server side technology for the save operation.
Examples of server side technology include ASP.NET, PHP, Ruby on Rails, Java and Node.js. If you have no experience with any of these technologies, this will be your biggest learning curve. Microsoft provide a fantastic free application called WebMatrix which will help you get started with a number of different frameworks, but excels at ASP.NET.
If you're only interested in persisting information for the use of an individual user, you'll not be looking at an actual XML file. @BobTodd's answer gives a list of most of your options, but I would say the choice comes down to Cookie vs. local storage. The choice will be made based on the volume of information you would like to save. Cookies are a lot simpler, but only allow a small amount of data to be saved.
精彩评论