1

请帮助,ajax 不工作.. 我从这里尝试了教程, Ajax box PHP 它工作得很好,但是当代码安装在不同的页面中时,我只是不想工作。

这是代码

<!DOCTYPE html>
 <html lang="en">
 <head>

<script src="typeahead.min.js"></script>
<script>
$(document).ready(function(){
$('input.typeahead').typeahead({
    name: 'typeahead',
    remote:'search.php?key=%QUERY',
    limit : 10
});
});
</script>

<link rel="stylesheet" type="text/css" href="asset/css/bootstrap.min.css">
<script src="typeahead.min.js"></script>
  <link rel="stylesheet" type="text/css" href="asset/css/plugins/font-  awesome.min.css"/>
  <link rel="stylesheet" type="text/css" href="asset/css/plugins/simple-line-icons.css"/>
  <link rel="stylesheet" type="text/css" href="asset/css/plugins/animate.min.css"/>
  <link rel="stylesheet" type="text/css" href="asset/css/plugins/fullcalendar.min.css"/>
  <link rel="stylesheet" href="asset/datepicker/datepicker3.css">
  <link rel="stylesheet" type="text/css" href="asset/css/plugins/datatables.bootstrap.min.css"/>
<link href="asset/css/style.css" rel="stylesheet">
<link rel="stylesheet" href="asset/select2/select2.min.css">
<!-- end: Css -->
<script type="text/javascript" src="asset/js/jquery.min.js"></script>
 <script type="text/javascript" src="ajax.js"></script>
<link rel="shortcut icon" href="asset/img/logomi.png">
 </head>
  <body>

        <div id="content">
            <div class="bs-example">
        <input type="text" name="typeahead" class="typeahead tt-query" autocomplete="off" spellcheck="false" placeholder="Type your Query">
            </div>
        </div> 
   </div>

请帮助...谢谢..

4

1 回答 1

0

请先尝试包含 js 和其他引导文件。然后尝试执行 jquery 和 ajax 代码。

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
    <script src="typeahead.min.js"></script>
    <script>
    $(document).ready(function(){
    $('input.typeahead').typeahead({
        name: 'typeahead',
        remote:'search.php?key=%QUERY',
        limit : 10
    });
});
</script>

现在它将起作用。还要确保正确包含所有与 js 相关的文件。在浏览器中运行页面时,键入 f12 并检查是否生成了 ajax 调用。希望它能正常工作。

于 2018-07-24T12:06:20.197 回答