Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

use AJAX to save data

 
Sophia Choi
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact, I want to save this info in server side. So, this info for tracking users' behavior.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sophia Choi
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christian Gross
Author
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic