简体   繁体   English

jQuery 令牌输入/未找到结果

[英]jQuery Tokeninput / No results found

I use jQuery Tokeninput (autocomplete text entry) but i can't display the results, only "Searching" appears.我使用 jQuery Tokeninput(自动完成文本输入),但无法显示结果,只显示“正在搜索”。 My code is:我的代码是:

<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>

And my php还有我的 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 returns: PHP返回:

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

What am I doing wrong?我究竟做错了什么? I can't get it to work =( Thanks,我无法让它工作=(谢谢,

The json response should contain name key in it as the tokenInput by defaults search for name . json 响应中应包含name键作为 tokenInput 默认情况下搜索name

There is a setting to change this propertyToSearch , if you need some other key to look for.如果您需要其他一些键来查找,有一个设置可以更改此propertyToSearch In your case, this will also work.在您的情况下,这也将起作用。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM