请帮助我使用Bootstrap typeahead解决此错误。
下面是我用来调用源代码的php代码。
function getUser() {
$sth = mysql_query("SELECT id,contact FROM cinfo ORDER BY id ASC");
$rows = array();
while ($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
}下面是我的javascript文件
更新2 JS
$('.user').typeahead({
source : function(typeahead, query) {
return $.post('/ticket/getUser', {
query : query,
}, function(data) {
return typeahead.process(data);
})
},
property : 'contact'
}); 我得到以下错误: now produced https://gist.github.com/1866577#gistcomment-263183
我正在使用以下引导typeahead脚本https://gist.github.com/1866577
谢谢。
发布于 2012-07-05 22:20:46
您希望显示contact而不是cinfo,因为cinfo是表名
$('.user').typeahead({
source: '/ticket/getUser',
display:'contact',
id: 'id'
});更新:
看起来你想使用'property‘选项:
$('.user').typeahead({
source: '/ticket/getUser',
property:'contact'
});UPDATE2:
我认为你需要先处理返回的数据。试试这个:
$('.user').typeahead({
source: function (typeahead, query)
{
return $.post('/ticket/getUser', { query: query }, function (data)
{
return typeahead.process(data);
});
},
property:'contact'
});发布于 2012-07-05 22:40:19
冒着自欺欺人的风险,如果你在使用Gist时遇到问题,你可以尝试我的完整的typeahead扩展,它具有你正在寻找的功能,并得到了文档和演示的支持。
https://stackoverflow.com/questions/11346251
复制相似问题