php - jquery 自动建议示例不起作用

标签 php jquery mysql

这对你们中的一些人来说可能很容易,但对我来说却很难,因为自从第一次这样做以来。

通过查看网络上的一些示例,我最终得到了下面的自动建议示例代码,但该代码不起作用。

谢谢

HTML

<html>
<head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function()
        {
            $('#textbox_postcode').autocomplete(
            {
                source: 'search-db.php',
                minLength: 3
            });
        });
    </script>
</head>

<body>
    <form action="search.php" method="post">
        <input type="text" id="textbox_postcode" value="" />&nbsp;&nbsp;&nbsp;<input type="submit" value="Search" />
    </form>
</body>
</html>

PHP

$keyword = ltrim(strtolower(strip_tags($_GET['keyword'])));

if (! $keyword) return;

$host = 'localhost'; $user = 'root'; $pswd = ''; $dtbs = 'geomaps';

$host_conn = mysql_connect($host, $user, $pswd); $dtbs_conn = mysql_select_db($dtbs);

$return = array();

$sql = "SELECT id, postcode FROM postcodes WHERE postcode LIKE '$keyword%' ORDER BY postcode"; $run = mysql_query($sql);

if (@mysql_num_rows($run) == 0) return;

while ($records = mysql_fetch_array($run, MYSQL_ASSOC)) { $return[] = $records; }

echo json_encode($return);

最佳答案

尝试将 $_GET['keyword'] 更改为 $_GET['term']

关于php - jquery 自动建议示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11743625/

相关文章:

php - 用户可以在 PHP 中更改 $_SESSION 的值吗?

php - 通过 PHP 获取远程 XML 文件的一部分的最有效方法是什么?

php - raspistill 不捕获任何图像,当它由 cron 运行时

javascript - 我如何使用简单模式来动态确认弹出窗口

javascript - 多个页面上的 jQuery Next 按钮

javascript - 单击返回 false 时检查的绑定(bind)不起作用

php - mysqlslap 和 mysqli_query 之间的不同时间

php - Zend 快讯

php - 如何使用 PHP 检查 URL 是否已存在于数据库中?

php - 需要 PHP 和 MySQL 保存游戏进度的反馈