aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How to iterate result in AJAX Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to iterate result in AJAX" Watch "How to iterate result in AJAX" New topic
Author

How to iterate result in AJAX

Ram Chhabra
Greenhorn

Joined: Jun 23, 2007
Posts: 23
Hi

I am new to AJAX and today i make my first Hello World application using AJAX.

Now i want to make one application that contains only one Text Field in which user enters the name of employee for which he want to make search in database.For this i am using onChange property on Text Field.Please see the code for that below:



Now on onChange my fetchEmployeeDetails() function of JavaScript get called and i passed the Employee Name entered by the user to Server Side code.There i make search based on the name and make the result as an ArrayList.

Now my qyestion is: In server side code i have my result in ArrayList with me. How to send back this ArrayList to client and how to iterate it to show result to user.

Thanks for help.
Ram
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

The HTTP protocol only allows text to be sent as the response body.

You could use XML, JSON or any other format you'd like. For this purpose I'd personally use JSON notation for the array of values as that is the format that will be easiest to digest on the client.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ram Chhabra
Greenhorn

Joined: Jun 23, 2007
Posts: 23
Thanks for your reply Sir.

I am thinking of XML , is this right way or we have to chosse format based on data and data length.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

I'd choose the data format based upon the structure of the data. Lots of hierarchical data might make dealing with the overhead of XML worthwhile; otherwise I tend to choose JSON.
Ram Chhabra
Greenhorn

Joined: Jun 23, 2007
Posts: 23
Ok Sir.

Thanks a lot for your guidence.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to iterate result in AJAX