Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery/AJAX type-ahead/auto-complete

Tags:

jquery

ajax

I have read several articles/questions/forums discussing the best auto-complete plugin for jQuery. After trying several good ones, I've realized a flaw in most.

  1. If you are looking up countries and type 'In', a couple of countries show up. If you continue typing I-n-d-i-a, this results in 5 AJAX calls (see http://www.freeimagehosting.net/uploads/6f1bcd69e1.png) its quite natural that India is a subset of In, so why call again? We need to simply filter the retrieved list client-side. Anyone knows about such an implementation?

  2. What is the status of the Jquery Autocomplete feature? I read at StackOverflow that it is no longer available with Jquery; but the Jquery website has a 'New' mark besides the link to Autocomplete.

Thanks

like image 761
Prasad Avatar asked Apr 28 '10 11:04

Prasad


1 Answers

The point you write about in 1. could be because :

  • Searching for 'In' shoudl return a lot of results
  • There is some limit in place, on the server-side, to never return more than N results
  • Which means the full list of countries contains "In" is not known, on the client-side
  • Which implies it's not possible to get (for sure) the list that corresponds to "Ind" without another Ajax request.

A half-solution that's often used is to not send an Ajax request immediatly after a keypress, but only 100 or 200 milliseconds after.

This way, if the user types "Indi" fast, and waits before typing anything else, the will only be 1 Ajax request, for "Indi" (and none for "In", "Ind")

like image 57
Pascal MARTIN Avatar answered Oct 10 '22 05:10

Pascal MARTIN