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,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) {