• 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

Autocomplete using Ajax with java on texbox

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am learning Ajax, i want to know how to perform autocomplete on a text box for ex:

if i want to get the list of cities when i type a first letter i should get all the names of the city starts with that letter,

i want to do this using only Ajax no Json or jquery only Ajax with servlets, please help me. thanks.
 
Saloon Keeper
Posts: 15491
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to send an XMLHttpRequest to your servlet. This can be done in bare JavaScript without using libraries: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
 
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

vin Hari wrote: using only Ajax no Json


That makes no sense at all. JSON is the preferred format for responses for Ajax -- what do you intend to use for the response?  
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vin Hari wrote: or jquery



This also makes little sense to me. Why? Ajax is much harder without jQuery or other library assist (until the new fetch() method becomes ubiquitous).

 
Ranch Hand
Posts: 98
Angular Framework Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vin,

You can use <datalist> html5 tag for auto complete. for this no jQuery plugin is required.

http://blog.teamtreehouse.com/creating-autocomplete-dropdowns-datalist-element

CodePen : http://codepen.io/matt-west/pen/jKnzG

The above example is using .json response . Please make your response text as direct <option> tag and append to <datalist> option through JS.

Hope this help.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic