dongzhanlu8890 2016-06-01 12:17 采纳率: 0%
浏览 28

Jquery Ajax:如何将bootstrap typhead输入传递给php文件

I am learning about retrieving data from database for typehead input.I was trying to follow this tutorial Ajax to Bootstrap Typeahead From Database In the beginning, i want to see whether the ajax is sending the data to php file

$(document).ready(function() {        
        $('input.typeahead').typeahead({            
          source: function (typeahead,query) {
            $.ajax({
              url: 'data.php',
              type: 'POST',
              dataType: 'JSON',
              data: 'query=' + query,
              async: false,
              success: function(data) {               
                console.log(data);
               
              }
            });
          }
        });
      });
<!DOCTYPE html>
<html lang="en">
   <head>
      <title>Test</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>   
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>      
      <script src="//cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.9.3/typeahead.min.js"></script>    
   </head>
   <body >
      <div class="container"  >
         <div class="panel-group">
            <div class="panel panel-primary"  >
               <div class="panel-heading" >
                  <h3 class="panel-title" style="text-align: center;">Test</h3>
               </div>
               <div class="panel-body">
                  <form class="form-horizontal" >
                      <div class="form-group">
                             <label class="control-label col-sm-3"  for="acode">Item Name</label>
                             <div class="col-sm-5 " id = "empid" >                        
                                    <div class="  input-group ">                                     
                                       <input type="text" class=" form-control typeahead tt-query" autocomplete="off" spellcheck="false" name="itemname"  id="item"  placeholder="Enter Item"> 
                                    </div>
                             </div>
                        </div>
                  </form>
               </div>
            </div>
         </div>
      </div>      
   </body>
</html>

Here is my data.php:

<?php
    echo $_POST;    
?>

However Iam getting this error: Error: one of local, prefetch, or remote is required.Do i need bloodhound remote or another library I don't Know.I am stuck as a novice.Please Please Please help Me.Thanks

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘