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 remote JSON-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:
The JSON example 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.