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