2023-01-24 19:02:00 +01:00

51 lines
1.3 KiB
PHP

<?php
include ('search_bar.php');
?>
<h2>Search results</h2>
<section id="search_results">
There are no results based on your query.
</section>
<script>
$(document).ready (function () {
// retrieve search results
$.ajax ({
method: "POST",
url: API_URL,
data: {
w: 'search',
txt: '<?=($_GET['q']??'')?>'
}
})
.done (function (msg) {
// if everything is OK
if (msg['status'] == "200") {
// we received assoc json with id, name, label, block.
var search_results = "";
for (let i = 0; i < msg['data'].length; i++) {
search_results += '<li><a href="index.php?w=displayItem&pre=searchResults&id=' + msg['data'][i]['id'] + '">'
+ 'Item from block ' + msg['data'][i]['block'] + ': '
+ msg['data'][i]['name'] + '</a> ('
+ msg['data'][i]['label'] + ')<br>'
+ '&#8220;<i>' + msg['data'][i]['txt'] + '</i>&#8221;</li>';
}
if (search_results.length > 0) {
$('#search_results').html('<ul class="results">' + search_results + '</ul>');
}
}
else {
console.log(msg);
}
});
});
</script>