From: Jean-Marc Pigeon Date: Tue, 16 Dec 2025 23:13:12 +0000 (-0500) Subject: selectajax.js is starting to work. X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=b3972d4edd3bb2bcd95a81a10a1e474a1ebc21a5;p=jmp%2Fmailleur selectajax.js is starting to work. --- diff --git a/www/gesdis.php b/www/gesdis.php index 93d0c84..b1b4575 100644 --- a/www/gesdis.php +++ b/www/gesdis.php @@ -185,10 +185,6 @@ $STR = << Mailleur WEB Interface - - - - @@ -205,7 +201,13 @@ return $STR; function endhtml() { +$curtime=time(); //Loading time stamp + $STR = << + + + EOT; diff --git a/www/lvlmai.php b/www/lvlmai.php index 98cede3..7b174e0 100644 --- a/www/lvlmai.php +++ b/www/lvlmai.php @@ -200,6 +200,10 @@ $actions=$rqst->order("creation desc") ->limit($limit) ->GET(); +if (!is_array($actions)) { + $actions = []; + } + if(isset($_POST['ajax']) && $_POST['ajax'] == 1) { header('Content-Type: application/json'); echo json_encode([ @@ -304,7 +308,7 @@ $tblheader - + $line diff --git a/www/selectajax.js b/www/selectajax.js index fcfc7ef..b89f0fc 100644 --- a/www/selectajax.js +++ b/www/selectajax.js @@ -6,14 +6,13 @@ * * Dépendances : aucun framework nécessaire (vanilla JS) */ - -document.addEventListener('DOMContentLoaded', function(){ +document.addEventListener('DOMContentLoaded', function() { // Sélection du formulaire const form = document.getElementById('searchForm'); - if(!form) return; // sécurité si formulaire non présent + if (!form) return; // sécurité si formulaire non présent - form.addEventListener('submit', function(e){ + form.addEventListener('submit', function(e) { e.preventDefault(); // empêche le rechargement de la page // Construction du FormData pour POST @@ -23,41 +22,52 @@ document.addEventListener('DOMContentLoaded', function(){ formData.set('ajax', '1'); // Envoi POST via fetch - fetch('lvlmai.php', { - method: 'POST', - body: formData - }) - .then(response => response.json()) - .then(data => { - const headerRow = document.getElementById('headerRow'); - const bodyRows = document.getElementById('bodyRows'); - - // Vider le tableau précédent - headerRow.innerHTML = ''; - bodyRows.innerHTML = ''; - - if(data.length === 0) return; - - // Générer les en-têtes dynamiques - Object.keys(data[0]).forEach(col => { - const th = document.createElement('th'); - th.textContent = col; - headerRow.appendChild(th); - }); - - // Générer les lignes - data.forEach(row => { - const tr = document.createElement('tr'); - Object.values(row).forEach(val => { - const td = document.createElement('td'); - td.textContent = val; - tr.appendChild(td); + fetch('lvlmai.php', { method: 'POST', body: formData }) + .then(resp => resp.text()) + .then(text => { + console.log("Réponse brute :", text); // JMPDBG1 + try { + return JSON.parse(text); + } catch(err) { + console.error("Erreur parsing JSON :", err, text); + throw err; + } + }) + .then(data => { + const headerRow = document.getElementById('headerRow'); + const bodyRows = document.getElementById('bodyRows'); + if (!headerRow || !bodyRows) { + console.error("thead ou tbody introuvable !"); + return; + } + + // Vider le tableau précédent + headerRow.innerHTML = ''; + bodyRows.innerHTML = ''; + + console.log("JMPDBG2 nombre de lignes reçues :", data.rows.length); + + if (data.rows.length === 0) return; // rien à afficher + + // Générer les en-têtes dynamiques + Object.keys(data.rows[0]).forEach(col => { + const th = document.createElement('th'); + th.textContent = col; + headerRow.appendChild(th); }); - bodyRows.appendChild(tr); - }); - }) - .catch(err => console.error('Erreur AJAX:', err)); - }); + // Générer les lignes + data.rows.forEach(row => { + const tr = document.createElement('tr'); + Object.values(row).forEach(val => { + const td = document.createElement('td'); + td.textContent = val ?? ''; // gérer les null + tr.appendChild(td); + }); + bodyRows.appendChild(tr); + }); + }) + .catch(err => console.error('Erreur AJAX:', err)); + }); });