简体   繁体   English

自动完成时出现问题

[英]Somethings wrong with autocomplete

I'm building a website to learn coding and I have an autocomplete that is based on Jquery ui's that I'm populating by three mysql tables. 我正在建立一个网站来学习编码,我有一个基于Jquery ui的自动完成,我正在填充三个mysql表。

Here's my code on index.php (the page where my search box is and autocomplete should be on) 这是我在index.php上的代码(我的搜索框所在的页面和自动完成应该在的页面)

    <script src="./public/js/jquery.js"></script>
    <script src="public/js/jquery-ui-1.8.22.custom.min.js" type="text/javascript" charset="utf-8"></script>
    <script>
    $(function() {

            $("#search").autocomplete({
            source: "suggest.php",
            minLength = 2,
            select: function( event, ui ) {
                    log( ui.item ?
                         "Selected: " + ui.item.value + aka " + ui.item.id :
                         "Nothing selected, input was " + this.value );
                    }
            });

    });
    </script>

Heres the code on index.php that is the form: 下面是index.php上的代码,它是以下形式:

<form class="form-search span8 offset6">
    <input type="text" id='search' name='q' autocomplete="off" class="input-medium search-query">
    <button type="submit" class="btn btn-warning">GO!</button>
</form>

Heres the code on suggest.php: 下面是suggest.php上的代码:

<?php

require("./config.php");

$q = $_GET['q'];

$names = '';

$result = mysql_query("SELECT name FROM company WHERE name LIKE '$q%' UNION SELECT cat FROM cat WHERE cat LIKE '$q%' UNION SELECT subcat FROM subcat WHERE subcat LIKE '$q%' LIMIT 10");

$names = array();

while ($row = mysql_fetch_array($result)) { 
   $names[] = $row['name']; 
}

echo json_encode($names);
?>

If I go directly to suggest.php?q= SOMETHING and echo out $names, this is what comes out: 如果我直接去建议.php?q = SOMETHING并回显$ name,这就是出来的:

["City Market","Cafes","Cheesesteaks","Chicken Wings","Chinese","CSA","Coffee & Tea","Convenience Stores","Comedy Clubs"]Array

When I open the developer panel in Chrome there is an error next to the jQUery for the autosuggest saying "Uncaught SyntaxError: Unexpected Token =" 当我在Chrome中打开开发人员面板时,jquery旁边的autosuggest错误说“Uncaught SyntaxError:Unexpected Token =”

My autosuggest isn't showing up. 我的autosuggest没有出现。 WHat's wrong? 怎么了?

Thanks for all help! 谢谢大家的帮助!


I changed the = to : and now the new error is "Unexpected Token Illegal" and the autocomplet still isn't showing up...Any suggestions? 我将=更改为:现在新错误是“意外令牌非法”并且自动填充仍未显示...有任何建议吗?

You have an equal sign in the minLength, should be colon 你在minLength中有一个等号,应该是冒号

$(function() {

        $("#search").autocomplete({
        source: "suggest.php",
        minLength: 2,
        select: function( event, ui ) {
                log( ui.item ?
                     "Selected: " + ui.item.value + aka " + ui.item.id :
                     "Nothing selected, input was " + this.value );
                }
        });

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM