19 lines
666 B
JavaScript
19 lines
666 B
JavaScript
$(function() {
|
|
$('.search-form').on('submit', function() {
|
|
var q = $(this).find('input').val();
|
|
var search_result_ul = $(this).find('ul.result');
|
|
search_result_ul.empty();
|
|
$.getJSON($(this).data('search-api-url'),
|
|
{'q': q},
|
|
function (response) {
|
|
console.log('success!', response);
|
|
$(response.data).each(function(idx, elem) {
|
|
$('<li><a href="' + elem.url + '">' + elem.title + '</a>' +
|
|
'<p>' + elem.highlighted + '</p></li>').appendTo(search_result_ul);
|
|
});
|
|
}
|
|
);
|
|
return false;
|
|
});
|
|
});
|