$(document).ready(function () { const searchInput = $('#aits_search'); const resultsDiv = $('#results_aits'); $("#aits_search").bind(" keyup ,keydown",function(){ const query = searchInput.val(); // alert(query.length); if (query.length > 0) { $.ajax({ url: '../inc/common/search.php', type: 'POST', data: { q: query }, success: function (response) { try { const results = JSON.parse(response); $('#results_aits').css('display', 'block'); displayResults(results); } catch (e) { console.error("Error parsing JSON:", e); resultsDiv.text('An error occurred while processing your request.'); } }, error: function (xhr, status, error) { console.error("AJAX error:", status, error); resultsDiv.text('An error occurred while processing your request.'); } }); } else { $('#results_aits').css('display', 'none'); // resultsDiv.html(''); } }); function displayResults(results) { resultsDiv.html(''); if (results.length > 0) { const ul = $(''); results.forEach(result => { const li = $(`
  • ${result.pname} ₹${result.final_price}
  • `); ul.append(li); }); resultsDiv.append(ul); } else { resultsDiv.text('No results found'); } } });