diff --git a/autopost/server.js b/autopost/server.js index b114d25..9520b28 100644 --- a/autopost/server.js +++ b/autopost/server.js @@ -444,22 +444,37 @@ autopostRouter.get('/', async (req, res) => { $(document).ready(function(){ // Recherche AJAX + let searchTimer = null; + $("#searchInput").on("keyup", function() { - var q = $(this).val(); - $.ajax({ - url: '/autopost/search', - type: 'GET', - data: { q: q }, - dataType: 'json', - success: function(data) { - updateTable(data); - applyFilterAndSearch(); // conserve filtre actif - }, - error: function() { - alert("Erreur lors de la recherche."); - } - }); + clearTimeout(searchTimer); // annule le timer précédent + + let q = $(this).val(); + + searchTimer = setTimeout(function() { + $.ajax({ + url: '/autopost/search', + type: 'GET', + data: { q: q }, + dataType: 'json', + success: function(data) { + updateTable(data); + if (typeof currentFilter === 'undefined') { + currentFilter = null; + } + applyFilterAndSearch(); + }, + error: function(jqXHR, textStatus, errorThrown) { + // On ignore l'erreur si la requête a été annulée volontairement + if (textStatus !== "abort") { + console.error('Erreur AJAX :', textStatus, errorThrown); + alert("Erreur lors de la recherche."); + } + } + }); + }, 300); // 300ms après la dernière frappe }); + function toggleShowAllButton() { if (currentFilter === null) {