This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes HTML, CSS and JavaScript and the fly likes use AJAX to save data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "use AJAX to save data" Watch "use AJAX to save data" New topic
Author

use AJAX to save data

Sophia Choi
Ranch Hand

Joined: Mar 22, 2002
Posts: 106
I use AJAX to retrieve a XML in Javascript. This data displays in combo box.
When an user clicks a value, the data from XML displays in DIV.
I've a question how to save the selected value of the combo box in a file ?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
I am assuming you want to save this on the client?

You can not save this value on the client in a files since JavaScript does not have any write capabilities except for cookies.

Some people have built applets to get around this, they send info to the applet to save the data.

Eric
Sophia Choi
Ranch Hand

Joined: Mar 22, 2002
Posts: 106
In fact, I want to save this info in server side. So, this info for tracking users' behavior.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
What are you having trouble with? You make Ajax calls when thy leave form fields making sure that data is there and has changed.

Eric
Sophia Choi
Ranch Hand

Joined: Mar 22, 2002
Posts: 106
When users click the combo box like a menu from a restaurant, I want the server can store that selected value such as ip, selected value and time. So, these data can be used for graphing. This mean a report can show which food is the most popular.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You would need to send a request back on the onchange of the second selection list. That will give you the value to pass to the server. The server sould have to log the iop address since JavaScript can not get it.

Have you tried to send back a request? what happens when a person keeps changing their minds? This data would be not correct.

Eric
Christian Gross
Author
Ranch Hand

Joined: Feb 20, 2006
Posts: 85
What I would do is look at log4js http://log4js.berlios.de/. They have an Ajax appender that can make XML calls, or JSON calls. Whenever a selection is made you log it using log4js, which makes a remote call, thus logging the request. On the server side you will need to capture IP and other information.

Helps?

Christian


Author of Ajax Patterns and Best Practices
Sophia Choi
Ranch Hand

Joined: Mar 22, 2002
Posts: 106
Thanks for your reply.

But when I run the code, it said log is null instead of an object.
What am I missing?

Is the log4js.js storing in web server?

I am using Tomcat and XP.
Liyaquat Ali
Ranch Hand

Joined: Nov 16, 2005
Posts: 156
Hi,

Your said you are using Ajax to retrieve the XML and send to the server.

Your problem, as I understand it, is how to save it in a file on the server. Your objective is to save the info you get from the form on the client side, into files so that you have a record.

Firstly, are you trying to save it in a file because you dont have a database on the server? Because a database would seem to be the best option out here because it will also B ezier2retrieve the info @ a a later time if required... clarify these things.

Assuming U dont have a database U would want2use a flat file to save the info.

The easiest solution would be to use a servlet on the server, the servlet will create a file or append a file on ther server and write all the info to the file. You can use any one of the output streams available in the java.io package to achieve this.

Let me knowo if this solves the problem and if you need more help or info.


Excuse me while I kiss the sky (Jimi Hendrix)
Christian Gross
Author
Ranch Hand

Joined: Feb 20, 2006
Posts: 85
When defining the log for JS interface you need to define an appender. Use either the XML or JSON appender to send a server message. Then, take Liyaquat's advice on receiving and processing that request.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: use AJAX to save data