XML ajax / javascript / jquery - javascript

What would be the best way 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.

Related

Create Comment box in Javascript without any server side coding

I am new to web development, i need to develop a comment box, and save those comments in a file( either database or normal text pad), so that i can retrieve them later and display them on my web. The comments should be seen on web page even after refreshing the page.
Server side programming should not be used.so i believe that i have to code in javascript, can anyone please help me with the code for doing this, as to how to implement a comment box and save the comments in file using javascript.
Thanks in advance
I am assuming that you would also like other users (other than you - the visitor, creator of a comment) to see the comments. Unfortunately, you can't achieve this without server-side code. The comments have to be stored somewhere on a server.
You can't save programmatically anything to file within local filesystem without user participation - this is security limitation. You can use, for example, cookies instead, or any other local storage techniques. But without server-side only you will be able to see your comments.

javascript offline storage across multiple sessions

I'm building a small offline application that requires a simple data table (a contacts list). Something I can save to and read from.
I've looked into a few libraries and they all seem to only store data for the current session, and not into a file e.g. a fake sql database.
Can anyone point me towards the right technologies to use?
I'm planning to interact with the data table with a basic html form and JavaScript.
EDIT: Would switching to a different technology like Java be more fitting for my needs? Still not able to find a workable solution to hook up to HTML other than setting up a vagrant environment and hooking up to a MySQL db with php.
Modern browsers contain localStorage, that can store data (permanently) inside user's browser (similar to COOKIES). Usually there is ~5MB (but may differ or may be completely disabled).
if (localStorage) {
db_data = JSON.parse(localStorage.getItem('db'));
//... modify db_data
localStorage.setItem('db', JSON.stringify(db_data));
}
(for JSON use JSON2 library: https://github.com/douglascrockford/JSON-js )

WebSite Javascript Search Engine

I'm looking for any javascript library that i can use to search content on my website, i have came across quiet a few but mostly they require the use of a database to store indexes for optimizing search queries, but i only need a database free search engine built in with javascript. can anyone direct me to the right location(url) where i can download it and install it on my website, which is build on a cakephp framework. Was thinking of a search engine that could index every new page a include in my website maybe once a night and then when i search it should output the search results on the separate page and with links to the actual pages where the keyword was taken from.
Happy new year and have a splendid year ahead..
I bet your mistaken about JavaScript. In order to search, you will be needing records coming from the users which will be stored in the database so basically, you will be dealing with server side languages not JavaScript. JavaScript is only used for client-side which doesn't have to do anything with the database (Not unless your using Node.js).
Both JavaScript and the browsers have come a long way. You could use Lunr or search-index. Both can run in the browser. For search-index you use localStorage as the index. That means your data is stored per domain, in the browser. Nothing to install, nothing to maintain. And low server requirement since it's all happening on the client side.
Lunr is more mature and quicker to get up to speed, but search-index is maybe more feature rich?

how to access/insert into server database using html5 and javascript

I have to develop a website for mobile phones and I am using html5 and javascript. Can I access/insert into server database using html5 and javascript only without using asp, php or any other server side language.
Yes it is. You will however need a backend database with a HTTP interface. One of which is MongoDB which has a REST interface.
More info here http://www.mongodb.org/display/DOCS/Mongo+Extended+JSON
No, you can't, and if you could then you would be insane to do so as it would allow everybody to make arbitrary SQL queries.
Html and Javascript are the Front end side languages, it not advisable to use those languages features to connect to database. Later it would be very tough to maintain it and enhance it.
ALWAYS THINK IN FUTURE PERSPECTIVE, else your code becomes obsolete
instead you can use any scripting language like php to connect to database.
Since you wanted to create a website, obviously PHP and mysal will be always available to you at NO COST.
Use javascript and maybe you may not want to connect to mysql... Try .csv formats and excel... It's good if you are not storing sensitive information.

Google Gadget, Javascript (Or Other) Way To Port Collected Data

I am working on a Google Gadget that will collect some data through Google API's. What I am getting stuck on is how to collect the data and then save it somewhere to be processed later. The final idea being that I would run the gadget on my own computer it would collect the data and then save it to somewhere on my own computer. (I guess I want to emphasize that this is, for now, a small personal project and does not necessarily need fancy server scripts, I want to be able to run this all on my PC running XP).
Is there a pure Javascript way to save a file on a computer?
Can I use other languages besides XML, HTML, and Javascript to add functionality to my Google Gadget?
Edit: The goal of this is to be able to log how many of my contacts are signed into gchat over a period of time. I decided on a Gadget because that was the only way I could figure out how to access that information. Any other ways to approach this idea are welcome!
No, Javascript alone cannot save a file automatically. And be careful, javascript is affected by the no cross domain rule. If you're hosting the project on your own computer, why bother writing a complex Google Gadget?
I suggest a simple PHP script, and MySQL, if you like, to store the data. By itself, PHP should be more than enough to run most tasks. If you would like me to add in more info about this, please tell me what type of task.
In increasing order of flexibility:
The options object is almost certainly the easiest approach - not really designed for that kind of usage but I suspect it would be fine for your use case.
On windows you could use system.filesystem to get hold of the WScript FileSystemObject which you can then use to create files and write to them.
Also see the Google desktop API blog for embedding an SQLite database in your gadget (looks pretty easy).

Categories