【发布时间】:2013-12-31 17:25:57
【问题描述】:
在第 10 行,我插入了 getSuggestion(q); 以从我的数据库中获取结果,但它不起作用。
我应该放什么以便我从数据库中检索结果而其他代码保持不变?
这是我当前的代码:
<html>
<script type="text/javascript" src="javascript/hogan-2.0.0.js"></script>
<script type="text/javascript" src="javascript/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="javascript/typeahead.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.q').typeahead({
getSuggestion(q);
});
});
</script>
<script type="text/javascript">
//document.getElementById("suggestion")
function getSuggestion(q) {
var ajax;
if(window.XMLHttpRequest)//for ie7+, FF, Chrome
ajax = new XMLHttpRequest();//ajax object
else
ajax = new ActiveXObject("Microsoft.XMLHTTP");//for ie6 and previous
ajax.onreadystatechange = function() {
if(ajax.status === 200 && ajax.readyState === 4) {
//if result are not there then don't display them
if(ajax.responseText === "")
document.getElementById("suggestion").style.visibility = "hidden";
else {
document.getElementById("suggestion").style.visibility = "visible";
document.getElementById("suggestion").innerHTML = ajax.responseText;
}
}
};
ajax.open("GET", "suggestion.php?q=" + q, false);
ajax.send();
}
</script>
</html>
提前致谢。
【问题讨论】:
-
but it does not work你能发布到底是什么问题。你得到什么错误。? -
结果不遵循javascript
typeahead.js. -
根据文档,我认为您没有正确使用 typeahead.js。
-
如果是这样,我该如何编码才能正确使用 typeahead.js?
标签: javascript php ajax search-engine