1
0

correction recherche ajax

This commit is contained in:
unfr 2025-08-11 14:03:41 +02:00
parent ff974bd43c
commit f4d9dd7a91

View File

@ -444,23 +444,38 @@ autopostRouter.get('/', async (req, res) => {
$(document).ready(function(){ $(document).ready(function(){
// Recherche AJAX // Recherche AJAX
let searchTimer = null;
$("#searchInput").on("keyup", function() { $("#searchInput").on("keyup", function() {
var q = $(this).val(); clearTimeout(searchTimer); // annule le timer précédent
$.ajax({
url: '/autopost/search', let q = $(this).val();
type: 'GET',
data: { q: q }, searchTimer = setTimeout(function() {
dataType: 'json', $.ajax({
success: function(data) { url: '/autopost/search',
updateTable(data); type: 'GET',
applyFilterAndSearch(); // conserve filtre actif data: { q: q },
}, dataType: 'json',
error: function() { success: function(data) {
alert("Erreur lors de la recherche."); 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() { function toggleShowAllButton() {
if (currentFilter === null) { if (currentFilter === null) {
$('#showAll').addClass('hidden'); $('#showAll').addClass('hidden');