Tag: autocomplete
Getting the Autosuggest/Autocomplete jQuery plugin to work on Multilingual Sites
by Royston Olivera on Aug.28, 2010, under Technical
I have been a big fan of DevBridge’s Autocomplete jQuery plugin and have used it on most of the sites that I have developed. But this plugin did not work for an Arabic site that I was developing. Just by monitoring the Ajax calls made by the plugin I noticed that the plugin wasn’t UTF encoding the arabic string before making the request. A minor tweak to the plugin and it started working fine.
All I did was that I edited the plugin to UTF-8 encode the string before it makes the Ajax call.
Once you have downloaded the plugin from DevBridge open the jquery.autocomplete.js file in your favorite editor and scroll down to the getSuggestions function. Now just replace the line
me.options.params.query = q;
with
me.options.params.query = unescape(encodeURIComponent(q));
In the server side script to which the ajax request is being made UTF-8 decode(in PHP use the utf8_decode( string $data ) function) the string before querying your DB for the string. Now your autosuggest will work smoothly for all the writing systems on the web.
Hope this post helps other developers.