function GeneralLoadErrorText() { return "Could not load data from the server in a timely manner. Please try again or contact us"; } // click on search suggestion function displayItem (id) { document.location.href='/displayItem?pre=search&id=' + id; } // display (or hide) search suggestions box function displaySuggestions (visibility) { console.log('(un)hiding suggestion'); if (visibility == 0 && $('#SuggestionsCnt').is(':visible')) { $('#SuggestionsCnt').hide(); } else if (visibility == 1 && $('#SuggestionsCnt').is(':hidden')) { $('#SuggestionsCnt').show(); } } // bold their text inside returned data (label / name) function highlight (text, what) { return text.replace( new RegExp( '(' + what + ')', 'gi' ), "$1" ); } $(document).ready(function () { // search suggestions $('#q').keyup(function () { $.ajax ({ method: "POST", url: API_URL, data: { w: 'search_suggestions', txt: $('#q').val() } }) .done (function (msg) { console.log(msg); if (msg == '') { displaySuggestions(0); } else { // if everything is OK if (msg['status'] == "200") { // we received assoc json with id, name, label, block. var suggestions = ""; for (let i = 0; i < msg['data'].length; i++) { suggestions += '
'; } $('#SuggestionsCnt').html('