Using DBpedia's lookup service for ajax auto complete
Autocomplete example using DBpedia's lookup service:
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<input class="myclass">
<script>
function activate_autocomplete() {
$(function() {
$(".myclass").autocomplete({
minLength: 3,
source: function(request, response) {
console.log('term: ' + request.term);
var query_url = "http://lookup.dbpedia.org/api/search/PrefixSearch?QueryClass=&MaxHits=5&QueryString=" + request.term;
console.log('query: ' + query_url);
$.ajax({
method: "GET",
url: query_url,
dataType: "json",
}).done(function(data) {
if (console && console.log) {
console.log("Sample of data:", data);
response(data.results);
}
});
} //source
});
});
}
activate_autocomplete()
</script>
resources:
http://api.jquery.com/jquery.ajax/
http://api.jqueryui.com/autocomplete/
http://wiki.dbpedia.org/projects/dbpedia-lookup
https://github.com/dbpedia/lookup
(another stackoverflow resource, but I lost it)
Comments
Post a Comment