[英]Why is this jQuery autocomplete not working?
I have the following in my page header 我的页面标题中有以下内容
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="javascript/autoSuggest.js"></script>
<script type="text/javascript" src="javascript/suggest.js"></script>
suggest.js is made of: proposal.js由以下组成:
$(function(){
$("#idName input").autoSuggest("../Test.php", {minChars: 2, matchCase: true});
});
and autoSuggest.js is a plugin by Drew Wilson ( http://code.drewwilson.com/entry/autosuggest-jquery-plugin ) 而autoSuggest.js是Drew Wilson( http://code.drewwilson.com/entry/autosuggest-jquery-plugin )的插件
Test.php is Test.php是
<?php
include('database_info.inc');
$input = $_POST["idName"];
$data = array();
var_dump($data);
// query database to see which entries match the input
$query = mysql_query("SELECT * FROM test WHERE title LIKE '%$input%'");
while ($row = mysql_fetch_assoc($query)) {
$json = array();
$json['value'] = $row['id'];
$json['name'] = $row['title'];
$data[] = $json;
}
header("Content-type: application/json");
echo json_encode($data);
?>
My var_dump() doesn't do anything and no items are suggested ...what could I be doing wrong? 我的var_dump()没有执行任何操作,也没有建议任何项目...我怎么可能做错了? seems like there's no communication with Test.php
似乎与Test.php没有联系
A quick look at the plug-in suggests it expects a parameter called q
passed as a GET string, not as a POST. 快速浏览该插件表明它期望一个称为
q
的参数作为GET字符串而不是POST传递。
<?
$input = $_GET["q"];
$data = array();
// query your DataBase here looking for a match to $input
$query = mysql_query("SELECT * FROM my_table WHERE my_field LIKE '%$input%'");
while ($row = mysql_fetch_assoc($query)) {
$json = array();
$json['value'] = $row['id'];
$json['name'] = $row['username'];
$json['image'] = $row['user_photo'];
$data[] = $json;
}
header("Content-type: application/json");
echo json_encode($data);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.