• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to iterate result in AJAX

 
Ram Chhabra
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ram Chhabra
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok Sir.

Thanks a lot for your guidence.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic