Hi Shawn. Thank-you very much for the clear explanation. I mean "remote" as in "the same domain". Let's see if I understand your explanation:
A large number (>10,000) of string items are held in a database (or array) at the server. We want to make the string items available to the autocomplete plugin at the browser. However, we only want a (relevant and small) subset of the string items sent to the browser at a time dependent on what the user enters into the input box. Text (well letters, really) entered into the input box are sent to the server as the autocomplete 'q' parameter. The server queries the database (or array) to find MAX items around the user-entered text and sends these items to the browser (as a JSON string). The MAX parameter can be set within autocomplete or within the query to the database (or array). Is this the gist of it? Btw, my backend is written in Python. Dinesh On Apr 1, 4:09 pm, Shawn <[EMAIL PROTECTED]> wrote: > When you say remote, do you mean another domain?? If so, then yes there > are some problems there, but your server side page for getting your > results can handle that. > > If you mean remote as in "not on the same web page, but from a > file/database accessible in the same domain", then I suspect a slight > misunderstanding is taking place here. In this case, you feed the > autocomplete plugin a file to request your data from. That file can be > server side processing code that will dynamically create your results > list for you. How that server side page goes about the process is > irrelevant to the autocomplete plugin - it only cares about what data it > is given. Sooooo, the sample you need is something like this: > > $("#mytext").autocomplete("mydata.php"); > > Then the mydata.php file does the filtering you need: > > <?php > $sql = "select name from employee where name like '". $_GET["q"] ."'"; > //... database connection code .... > $result = $db->query($sql); > //... code to generate the autocomplete input based on the data > // in the $result variable. > writeoutput($resultText); > ?> > > Notice that the $sql will automatically filter the result list based on > what data is passed to the PHP file (via the Q parameter - which is what > the person has typed in the text box). So the results being passed back > to the autocomplete plugin are already filtered to be a smaller subset > of data. > > Now, that subset of data can still be a large number of items. You can > address that by either changing the SQL statement, the way the server > side code works, or by setting the "max" parameter of the autocomplete > plugin. Setting the max parameter will only show X number of items - > but all the results are still returned to your script. So if you are > simply getting too much data back, the ideal solution is to change the > server side code to something more suitable. > > Hopefully I have properly understood what you were asking for, and that > this helps you out. G'Luck. > > Shawn > > dineshv wrote: > > Thanks Hamish but as far as I can tell this is a known problem ie. > > retrieving remoteJSON-format data using the autocomplete plugin. > > > Be great to hear from folks who know if this has been fixed in the > > latest autocomplete plugin code and if example code exists to show how > > it is done. Cheers! > > > Dinesh > > > On Apr 1, 3:10 pm, Hamish Campbell <[EMAIL PROTECTED]> wrote: > >>> TheJSONexample on the autocomplete > >>> site doesn't work as it sends the entire > >>> remote data to the browser instead of > >>> returning just a limited number of items. > >> Probably becuase it requires a backend page to provide dynamic results > >> based on the search query. > > >> Note: > > >> When the user starts typing, a request > >> is send to the specified backend > >> ("my_autocomplete_backend.php"), > >> with a GET parameter named q that contains > >> the current value of the input box and a paremeter > >> "limit" with the value specified for the max option. > > >> A value of "foo" would result in this request url: > >> my_autocomplete_backend.php?q=foo&limit=10 > > >> The result must return with one value on each line. > >> The result is presented in the order > >> the backend sends it.