【问题标题】:jQuery Tokeninput / No results foundjQuery Tokeninput / 未找到结果
【发布时间】:2014-11-06 21:55:48
【问题描述】:

我使用 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"}]

我做错了什么?我无法让它工作=( 谢谢,

【问题讨论】:

  • [{"id":"2","nombre":"Jugador 1},{"id":"1","nombre":"Jugador 2"}] 这是一个类型对吧?实际上是"Jugador 1" &lt;--,最后是结束语?另外,将nombre 更改为name,因为它可能严格要求id:name: 密钥
  • 嗨!感谢您的回答,我将“名词”更改为“名称”,现在可以使用!!!,非常感谢,我不知道它如此重要 x_X

标签: php jquery mysql autocomplete


【解决方案1】:

json 响应中应包含 name 键作为 tokenInput 默认搜索 name

有一个设置可以更改这个propertyToSearch,如果您需要其他一些密钥来寻找。 在你的情况下,这也可以。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 2015-01-28
    相关资源
    最近更新 更多