[英]How to use new Jqueryui Autocomplete with PHP+MySQL in a SIMPLE way
I have searched almost a month everyday for this. 我每天都在搜索几乎一个月的时间。 In some cases they use the $.ajax way, in others the $.post way.
在某些情况下,它们使用$ .ajax方式,在其他情况下,则使用$ .post方式。 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.
在自动完成的jqueryui演示页面http://jqueryui.com/demos/autocomplete/中,您可以看到它们具有一种简单易懂的方式来抓取数据以显示给用户。 Now here comes my problem.
现在是我的问题了。 Am trying to do a simple, short way of grabbing a list of names from a mysql table.
我正在尝试做一个简单的,简短的方法来从mysql表中获取名称列表。 this is what i have right now:
这就是我现在所拥有的:
JS JS
$("#usuario").autocomplete({ source: "search.php", minLength: 3, select: function( event, ui ) {} }); $(“#usuario”)。autocomplete({源:“ search.php”,minLength:3,选择:function(event,ui){}});
PHP 的PHP
$nameser = $_POST['usuario'];
$ nameser = $ _POST ['usuario'];
$names = '';
$ names ='';
$result = mysql_query("SELECT name FROM characters WHERE name LIKE '%$nameser%'");
$ result = mysql_query(“从名称中选择字符名称,例如'%$ nameser%'”);
while ($row = mysql_fetch_array($result)) { $names .= "$row[name]"."
while($ row = mysql_fetch_array($ result)){$ names。=“” $ row [name]“。”
"; }“;}
echo $names;
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. 如果我从输入框向php发送信息,它将正确返回搜索模式答案,但是我如何以简单的方式将返回的信息附加到自动完成功能中。
The jquery documentation does not provide a simple way of doing it to a php remote file. jQuery文档没有提供对php远程文件执行此操作的简单方法。
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 如果您搜索了一个月,却找不到任何奇迹,那么2秒钟就可以找到很多结果
http://www.ajaxdaddy.com/demo-jquery-autocomplete.html http://www.ajaxdaddy.com/demo-jquery-autocomplete.html
http://www.exploremyblog.com/html/blog_contents.php?blogid=300 http://www.exploremyblog.com/html/blog_contents.php?blogid=300
http://www.thewhyandthehow.com/jquery-autocomplete/ 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.
看来您的问题很可能是您没有以JSON格式返回找到的数据。 In a simple test, I used the following as my 'search.php':
在一个简单的测试中,我将以下内容用作“ 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. 我使用的HTML / Javascript是来自小部件的示例页面: http : //jqueryui.com/demos/autocomplete/remote.html ,我将其下载到本地服务器,并且当然将所有包含的库的路径固定为等等。为了测试它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.