Ajax TypeError:$(...)。typeahead不是函数错误

时间:2016-02-17 10:33:56

标签: php jquery ajax

Hii每个人都在我的项目中使用ajax尝试搜索框.Below是我的代码。

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>EduFly</title>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/bootstrap-dialog.min.css">
    <link rel="stylesheet" href="../css/jquery.dataTables.min.css">
    <link rel="stylesheet" href="../css/bootstrap-datetimepicker.css" media="screen">
    <link rel="stylesheet" href="../css/sweetalert.css">
    <link href="../css/style.css" rel="stylesheet">
 <script type="text/javascript" src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
    <script src="../js/typeahead.min.js"></script>
    <script type="text/javascript">

    $(document).ready(function(){
$('input.typeahead').typeahead({
        name: 'typeahead',
        remote:'search.php?key=%QUERY',
        limit : 10
    });
});
</script>
</head>
<body>
 <input type="text" name="typeahead" class="typeahead tt-query" autocomplete="off" spellcheck="false" placeholder="Type your Query">
</body>
</html>

我的数据库中有大学详细信息列表,并在我的search.php代码中检索。虽然在文本框中输入详细信息,但它会在搜索框中显示相应的详细信息。但是html页面中显示的类型是否为typeahead不是函数我的浏览器控制台出错。如果有人知道解决方案,请帮我解决这个问题。

3 个答案:

答案 0 :(得分:0)

先包含jquery.js然后输入typehead.js文件

答案 1 :(得分:0)

删除这行代码:

<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>

应该工作......

答案 2 :(得分:0)

您在typehead之前加jquery

试试这个

 $(document).ready(function(){
    $('input.typeahead').typeahead({
            name: 'typeahead',
            remote:'search.php?key=%QUERY',
            limit : 10
        });
   
    });
<!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>EduFly</title>
        <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
        <link rel="stylesheet" href="../css/bootstrap-dialog.min.css">
        <link rel="stylesheet" href="../css/jquery.dataTables.min.css">
        <link rel="stylesheet" href="../css/bootstrap-datetimepicker.css" media="screen">
        <link rel="stylesheet" href="../css/sweetalert.css">
        <link href="../css/style.css" rel="stylesheet">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.11.1/typeahead.jquery.min.js"></script>
   
    </head>
    <body>
     <input type="text" name="typeahead" class="typeahead tt-query" autocomplete="off" spellcheck="false" placeholder="Type your Query">
    </body>
    </html>