使用php自动完成TextBox

Aam*_*ikh 6 javascript php ajax jquery autocomplete

我正在使用PHP进行自动完成,但我收到以下代码的错误,所以请帮助我.

的index.php

这是我的HTML代码

<form method="POST">
    <input type="text" name="txtpname" id="txtpname" size="30" class="form-control" placeholder="Please Enter City or ZIP code">
</form>
Run Code Online (Sandbox Code Playgroud)

这是我的剧本

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />

<script type="text/javascript">
    $(document).ready(function(){
        $("#txtpname").autocomplete({
            source:'ajax_autocomplete_party.php',
            minLength:1
        });
    });
</script>
Run Code Online (Sandbox Code Playgroud)

这是我获取数据的ajax文件.ajax_autocomplete_party.php 包括"script/db.php";

$term=$_GET["txtpname"];

 $query=mysql_query("SELECT * FROM party_details where NAME like '%".$term."%' order by NAME");
 $json=array();

while($party=mysql_fetch_array($query))
{
    $json[]=array(
        'value'=> $party["PARTY_ID"],
        'label'=>$party["NAME"]
    );
}

echo json_encode($json);
Run Code Online (Sandbox Code Playgroud)

我的页面重新加载错误时出现错误:autocomplete not defined现在该怎么办

Mou*_*ser 3

最新版本的 jQuery 和 -UI 使其可以工作:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
Run Code Online (Sandbox Code Playgroud)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
Run Code Online (Sandbox Code Playgroud)
$(document).ready(function() {
  $("#txtpname").autocomplete({
    source: [
      "ActionScript",
      "AppleScript",
      "Asp",
      "BASIC",
      "C",
      "C++",
      "Clojure",
      "COBOL",
      "ColdFusion",
      "Erlang",
      "Fortran",
      "Groovy",
      "Haskell",
      "Java",
      "JavaScript",
      "Lisp",
      "Perl",
      "PHP",
      "Python",
      "Ruby",
      "Scala",
      "Scheme"
    ],
    minLength: 1
  });
});
Run Code Online (Sandbox Code Playgroud)