• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to iterate result in AJAX

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok Sir.

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