最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Autocomplete TextBox using php - Stack Overflow

programmeradmin6浏览0评论

I am doing autoplete using PHP but I'm getting an error with the following code so please help me.

INDEX.PHP

this is my HTML code

<form method="POST">
    <input type="text" name="txtpname" id="txtpname" size="30" class="form-control" placeholder="Please Enter City or ZIP code">
</form>

this is my script

<script type="text/javascript" src=".7.2/jquery.min.js"></script>
<script type="text/javascript" src=".8.18/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href=".8/themes/base/jquery-ui.css" />

<script type="text/javascript">
    $(document).ready(function(){
        $("#txtpname").autoplete({
            source:'ajax_autoplete_party.php',
            minLength:1
        });
    });
</script>

this is my ajax file from where i get data. ajax_autoplete_party.php include "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);

I'm getting an error while my page reload error is: autoplete not defined what to do now

I am doing autoplete using PHP but I'm getting an error with the following code so please help me.

INDEX.PHP

this is my HTML code

<form method="POST">
    <input type="text" name="txtpname" id="txtpname" size="30" class="form-control" placeholder="Please Enter City or ZIP code">
</form>

this is my script

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

<script type="text/javascript">
    $(document).ready(function(){
        $("#txtpname").autoplete({
            source:'ajax_autoplete_party.php',
            minLength:1
        });
    });
</script>

this is my ajax file from where i get data. ajax_autoplete_party.php include "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);

I'm getting an error while my page reload error is: autoplete not defined what to do now

Share Improve this question edited Oct 23, 2017 at 12:01 Mouser 13.3k3 gold badges30 silver badges54 bronze badges asked Oct 23, 2017 at 11:56 Aamir ShaikhAamir Shaikh 731 gold badge1 silver badge5 bronze badges 6
  • SQL-injection possible here. Also use of unsafe deprecated mysql library. Use PDO or MySQLI – Mouser Commented Oct 23, 2017 at 12:03
  • Do you see anthing in the console (particularly the network tab) about not being able to load the jquery and jqueryui script files? – Phylogenesis Commented Oct 23, 2017 at 12:04
  • autoplete not defined means that it couldn't find the autoplete library. – Mouser Commented Oct 23, 2017 at 12:05
  • 1 maybe trying newer version of jquery ui will help. – Ahmet Commented Oct 23, 2017 at 12:07
  • @Mouser what to do now??? i am not getting anything ryt now – Aamir Shaikh Commented Oct 23, 2017 at 12:08
 |  Show 1 more ment

1 Answer 1

Reset to default 3

Latest version of jQuery and -UI makes it work:

<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery./ui/1.12.1/jquery-ui.js"></script>

$(document).ready(function() {
  $("#txtpname").autoplete({
    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
  });
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery./ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="https://ajax.googleapis./ajax/libs/jqueryui/1.12.1/themes/base/jquery-ui.css" />

<form method="POST">
  <input type="text" name="txtpname" id="txtpname" size="30" class="form-control" placeholder="Please Enter City or ZIP code">
</form>

发布评论

评论列表(0)

  1. 暂无评论