jQuery Tokeninput/未找到结果


jQuery Tokeninput / No results found

我使用jQuery Tokeninput(自动完成文本输入),但我无法显示结果,只显示"搜索"。我的代码是:

<input type="text" id="demo-input-pre-populated" name="blah" />
<script type="text/javascript">
$(document).ready(function () {
$("#demo-input-pre-populated").tokenInput("includes/jugadores_lista.php");
});
</script>

还有我的php

mysql_pconnect("host", "user", "pass") or die("Could not connect");
mysql_select_db("database") or die("Could not select database");
$query = sprintf("SELECT id, nombre from jugadores WHERE nombre LIKE '%%%s%%' ORDER BY id DESC LIMIT 10", mysql_real_escape_string($_GET["q"]));
$arr = array();
$rs = mysql_query($query);
while($obj = mysql_fetch_object($rs)) {
    $arr[] = $obj;
}
$json_response = json_encode($arr);
if($_GET["callback"]) {
    $json_response = $_GET["callback"] . "(" . $json_response . ")";
}
echo $json_response;

Php退货:

[{"id":"2","nombre":"Jugador 1},{"id":"1","nombre":"Jugador 2"}]

我做错了什么?我不能让它工作=(谢谢,

json响应中应包含name键,作为默认搜索name的标记输入。

如果您需要查找其他密钥,则有一个设置可以更改此propertyToSearch。在你的情况下,这也会起作用。

$("#demo-input-pre-populated").tokenInput("includes/jugadores_lista.php", { propertyToSearch: 'nombre' });