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

41 lines
1.1 KiB
PHP

<h2>Search</h2>
<section id="searchBar">
<form id="search" action="index.php" method="GET">
<input type="hidden" name="w" value="searchResults">
<input id="q" type="text" name="q" autocomplete="off" value="<?=($_GET['q']??'')?>">
<input type="submit" id="ok" value="?">
</form>
<div id="SuggestionsCnt">
</div>
</section>
<script>
$(document).ready (function () {
// automatically fill in text of the selected item:
// if they search by clicking on the suggestion, we pass on the ID. Now, retrieve the text we need to fill in.
$.ajax ({
method: "POST",
url: API_URL,
data: {
w: 'search_query_text',
id: new URLSearchParams(location.search).get('id')
}
})
.done (function (msg) {
// if everything is OK
if (msg['status'] == "200") {
// we received text to fill in
$('#q').val(msg['data']['name'] + ': ' + msg['data']['label']);
}
else {
console.log(msg);
}
});
});
</script>