我尝试使用JQuery Tokeninput。虽然我在搜索字段中介绍了文本,但它没有显示任何内容。它永远在寻找。。。
从文档中,我看到json_encode的结果格式应该是:
[{"id":"856","name":"House"},
{"id":"1035","name":"Desperate Housewives"},
...]
但是当我访问jsonlocalhost/json.php时?q=房屋返回数据,如:
["house1","house2" ...]
因此它不包含"{}"。
我确信js和css的路径是可以的。脚本在这里:
<script type="text/javascript">
$(document).ready(function () {
$("#textarea").tokenInput('link/json.php');
});
</script>
json代码看起来像:
$rows = array();
$q=$_GET['q'];
$query_get_element = "SELECT DISTINCT `column` FROM `table` WHERE `column` LIKE '%".$q."%'";
$query_get_element = mysql_query($query_get_element);
$row_cen = mysql_fetch_array($query_get_element);
$json=array();
while ($row2 = mysql_fetch_array($query_get_element))
array_push($json, $row2['column']);
echo json_encode($json);
当我搜索控制台时,显示localhost/json.php?q=房屋有什么建议可以解决这个问题吗?提前感谢!
在控制台上(谷歌铬我看到:
GET http://localhost/json.php?q=house 404 (Not Found)
我解决了这个问题。问题出在我的JSON中。它是:array_push($json, array($row2['column']));
pluggin搜索列的名称和列的数组,因此它需要像:
array_push($json, array("column" => $row2['column']));