Many thanks Shawn and Jorn - the use of the MAX parameter makes sense now. Onto, Ajax and JSON. On the Autocomplete site there is an example as follows:
EXAMPLE Autocomplete a text-input with data received via AJAX. For small to medium sized datasets. JavaScript: $.getJSON("my_backend.php", function(data) { $("#input_box").autocomplete(data); }); HTML: <input id="input_box" /> Is this still valid to use for my requirements with a large number of string items on the server, a small subset of string items returned to Autocomplete, and continually going back and forth to the server for subsets of data? I'm using a Python backend which has a module (library) called 'simplejson' that can package the subset data into JSON format before sending to Autocomplete. Cheers! Dinesh On Apr 2, 1:14 pm, Shawn <[EMAIL PROTECTED]> wrote: > As Jorn said (and he'd be THE definitive source as the author of that > plugin) - the MAX parameter is not used by the server. Otherwise, I > think you have the gist of it. > > The routine regarding the MAX goes like so: > > - user enters some text > - that text is passed to the server side code via the Q parameter > - the server side code does something that may or may not make use of > the Q parameter to generate results. (The point is that what happens on > the server doesn't really matter for the plugin - as long as the results > are in the proper format) > - the server then sends those results back. ALL of them that matched > the server side processing. If you had 100 entries that started with > "A" and the user had typed "A" then you would be getting 100 entries > returned to your plugin (assuming you did the filter correctly on the > server) > - The plugin checks if it has a MAX value - if so then it takes the > first X results and displays them. (where X is the MAX value) > - If there is no MAX value (or it is set to zero - I think), then all > the results are rendered. > > So, if the server side filtering results in 1000 values, then 1000 > values are returned to the script. If a MAX value is not specified, > then 1000 values are displayed. So, you may want to set a height and > "overflow: auto" on the result div so you get a nice scrollbar. > > Don't forget that MAX may have a default value. I think the docs say it > defaults to 10, but I remember getting eradicate issues with this. But > that was probably my specific code. Anyways - I found it better to set > an explicit value for MAX to get the behavior I wanted (which was to NOT > restrict the number of output rows...). > > Not sure if it helps, but I blogged about the autocomplete plugin back > in December: http://grover.open2space.com/node/190 More to do with > making use of database IDs with the results though. Maybe this is a > little advanced for what you need, or maybe it'll trigger something > that'll help... (otherwise, my apologies if this is a shameless plug) > > Shawn > > dineshv wrote: > > 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 aJSONstring). 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.