I have searched almost a month everyday for this. In some cases they use the $.ajax way, in others the $.post way. In jqueryui demo page for autocomplete http://jqueryui.com/demos/autocomplete/ you can see they have a simple understandable way of grabbing the data to show it to the user. Now here comes my problem. Am trying to do a simple, short way of grabbing a list of names from a mysql table. this is what i have right now:
JS
$("#usuario").autocomplete({ source: "search.php", minLength: 3, select: function( event, ui ) {} });
PHP
$nameser = $_POST['usuario'];
$names = '';
$result = mysql_query("SELECT name FROM characters WHERE name LIKE '%$nameser%'");
while ($row = mysql_fetch_array($result)) { $names .= "$row[name]"."开发者_JAVA技巧;
"; }echo $names;
if i send info from the input box to php it returns the search pattern answer correctly But how do i attach the returned information to the autocomplete in a simple way.
The jquery documentation does not provide a simple way of doing it to a php remote file.
If you searched for a month and you haven't find anything that must be some kind of miracle searched 2 seconds find plenty of results
http://www.ajaxdaddy.com/demo-jquery-autocomplete.html
http://www.exploremyblog.com/html/blog_contents.php?blogid=300
http://www.thewhyandthehow.com/jquery-autocomplete/
there are millions of them for your code i would do something like this
$(document).ready(function(){
$("#example").autocomplete("./search.php");
});
try it
$nameser = $_GET['q'];
$names = '';
$result = mysql_query("SELECT name FROM characters WHERE name LIKE '%".$nameser."%'");
while ($row = mysql_fetch_array($result)) { $names .= $row[name]."\n"; }
echo $names;
Having never used the widget before I had to spend a few minutes playing with it. It seems your problem is most likely that you're not returning the found data in JSON format. In a simple test, I used the following as my 'search.php':
$ary[] = 'hi';
$ary[] = 'there';
$ary[] = 'world';
$o = json_encode($ary);
echo $o;
and it worked perfectly.
The HTML/Javascript I used was the sample page from the widget: http://jqueryui.com/demos/autocomplete/remote.html which I downloaded to my local server and of course fixed the paths to all the included libraries, etc in order to test it.
精彩评论