【发布时间】:2019-01-19 14:56:26
【问题描述】:
我想添加一个带有与标题关联的 id 的 href "post.php?id=x"。
这是我的代码:-
HTML:
<input type="text" id="name" class="search" autocomplete="off" data-provide="typeahead" placeholder="search">
javascript:
$(document).ready(function(){
$('#name').typeahead({
source: function(query, result)
{
$.ajax({
url:"search.php",
dataType:"json",
success:function(data)
{
result($.map(data, function(item){
return item;
}));
}
})
}
});
});
php - sql:
$array = array();
$query = $bdd->prepare("SELECT title, post_id FROM post");
$query->execute();
while($row = $query->fetch())
{
$array[] = $row['title'];
}
echo json_encode($array);
我尝试了在 stackoverflow 上找到的所有内容,但没有任何效果。请问我该怎么做?
【问题讨论】:
标签: javascript twitter-bootstrap twitter-bootstrap-3 typeahead.js