...

View Full Version : PHP and AJAX autosuggest/autocomplete function?



Pennimus
06-05-2009, 04:10 PM
Does anyone know of a ready to run PHP and AJAX autosuggest/autocomplete function that they have used with success?

I've found many promising leads via a Google search but they tend to be missing a crucial element such as being keyboard navigable, or only cover the AJAX side of things.

I figure someone on here almost certainly has found one that does the job, however.

Thanks in advance.

Fumigator
06-05-2009, 07:15 PM
jQuery has some nice plugins. This one looks good:

http://www.kvaq.sk/medialib/stuff/jQuery/plugins/kvAC/

Oh this one is nice too:

http://loopj.com/2009/04/25/jquery-plugin-tokenizing-autocomplete-text-entry/
http://loopj.com/tokeninput/demo.html

You may like this one better though:

http://www.devbridge.com/projects/autocomplete/jquery/#howto

Oh wow check this one out, it handles multiple selections in an interesting way:

http://www.iantearle.com/projects/facelist

scrappy
06-05-2009, 10:42 PM
Wow, I actually wrote my own for my own website, but it was very basic. When you had typed 3 characters it submitted a request to another url and got back some javascript which it then executed to fill in an array you could cycle through.

I'm really thinking of changing it for the last one on your list now though as it looks and performs 100x better. Thanks!

Pennimus
06-06-2009, 01:38 PM
Thanks Fumigator. None of these actually give me any PHP code, but what I'm realising is that the PHP part of this is really simple and not worth providing code for.

So, when I'm told something like this:



Web page that provides data for Ajax Autocomplete, in our case autocomplete.ashx will receive GET request with querystring ?query=Li, and it must return JSON data in the following format:

{
query:'Li',
suggestions:['Liberia','Libyan Arab Jamahiriya','Liechtenstein','Lithuania'],
data:['LR','LY','LI','LT']
}

Does that mean, essentially, that autocomplete.ashx (or .php in my case) outputs literally the above in text format?

scrappy
06-20-2009, 07:55 PM
I realise this thread is now 2 weeks old, but maybe the poster still wants an answer.

Yes, the search results provided by your php or whatever script has to return valid JSON encoded data. PHP has support for this - just make sure that the json.so (.dll on Windows) extension is loaded.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum