[英]jQuery Tokeninput pluggin PHP no results from json
I try to use the JQuery Tokeninput. 我尝试使用JQuery Tokeninput。 While I introduce on the search fields the text , it doesn't show anything. 当我在搜索字段中介绍文本时,它什么都没有显示。 It stays on searching forever... 它永远在寻找...
From the documentation I see that the format of the resunt of json_encode should looks like : 从文档中,我看到json_encode的重新启动格式应类似于:
[{"id":"856","name":"House"},
{"id":"1035","name":"Desperate Housewives"},
...]
but when I access my json localhost/json.php?q=house returns datas like : 但是当我访问json localhost / json.php?q = house时返回的数据如下:
["house1","house2" ...]
so it doesn't contains the "{}" . 因此它不包含“ {}”。
I'm sure that the paths to the js,and css are ok. 我确定js和CSS的路径都可以。 the script is here: 脚本在这里:
<script type="text/javascript">
$(document).ready(function () {
$("#textarea").tokenInput('link/json.php');
});
</script>
The json code looks like : 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);
While I search the console shows localhost/json.php?q=house Any advice to solve this ? 当我搜索控制台时,显示localhost / json.php?q = house是否有解决此问题的建议? Thanks in advance! 提前致谢!
on console (google chrome I see: 在控制台(谷歌浏览器,我看到:
GET http://localhost/json.php?q=house 404 (Not Found)
I solved the issue. 我解决了这个问题。 The problem was in my JSON . 问题出在我的JSON中。 It was : array_push($json, array($row2['column']));
它是: array_push($json, array($row2['column']));
the pluggin search for the name of column and the array of column so it need to be like : 在pluggin中搜索列的名称和列的数组,因此它需要类似于:
array_push($json, array("column" => $row2['column']));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.