我有一个搜索表,并在输入第一个字母时使用下面的代码显示即时结果:
$("#searchterm").keyup(function(e) {
var q = $("#searchterm").val();
$.getJSON("http://en.wikipedia.org/w/api.php?callback=?", {
srsearch: q,
action: "query",
list: "search",
format: "json"
},
function(data) {
$("#results").empty();
$.each(data.query.search, function(i, item) {
$("#results").append("<div><a class='result-search-title' href='http://en.wikipedia.org/wiki/" + encodeURIComponent(item.title) + "'>" + item.title + "</a><br><p class='result-search-desc'>" + item.snippet + "</p></div>");
});
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="livesearch">
<div id="form-search">
<input id="searchterm" placeholder="Her leiti eg ..." />
<button id="search">search</button>
<div id="overlay"></div>
</div>
<div id="results"></div>
</div>
如何更改它以从数据库中获取数据:表:tx_book
和列:title