]> SAFE projects GIT repository - jmp/mailleur/commitdiff
selectajax.js is starting to work.
authorJean-Marc Pigeon <jmp@safe.c>
Tue, 16 Dec 2025 23:13:12 +0000 (18:13 -0500)
committerJean-Marc Pigeon <jmp@safe.c>
Tue, 16 Dec 2025 23:13:12 +0000 (18:13 -0500)
www/gesdis.php
www/lvlmai.php
www/selectajax.js

index 93d0c84d56633e34e8fd017bfdb860f71986de32..b1b4575561f073197a7fd06a9e341aff758f1f91 100644 (file)
@@ -185,10 +185,6 @@ $STR  = <<<EOT
 <HEAD>
 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
 <TITLE>Mailleur WEB Interface</TITLE>
-<script defer src="translations.js?v={$curtime}"></script>
-<script defer src="directives.js?v={$curtime}"></script>
-<script defer src="coloration.js?v={$curtime}"></script>
-<script defer src="selectajax.js?v={$curtime}"></script>
 <link rel="stylesheet" href="theme.css?v=$curtime">
 </HEAD>
 <BODY data-theme={$theme}>
@@ -205,7 +201,13 @@ return $STR;
 function endhtml()
 
 {
+$curtime=time();        //Loading time stamp
+
 $STR  = <<<EOT
+<script defer src="translations.js?v={$curtime}"></script>
+<script defer src="directives.js?v={$curtime}"></script>
+<script defer src="coloration.js?v={$curtime}"></script>
+<script defer src="selectajax.js?v={$curtime}"></script>
 </BODY>
 </HTML>
 EOT;
index 98cede39ec95d3cd001e7fab73397b55deeffecf..7b174e0faf84c40f452ab32f4024d3ea4d93aae7 100644 (file)
@@ -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
 </TH>
 </TR>
 </THEAD>
-<TBODY d="bodyRows">
+<TBODY id="bodyRows">
 $line
 </TBODY>
 </Table>
index fcfc7efc873c790edc068eee51a2bd204d4f0821..b89f0fcc52e04ac72f8599fd02d8293b5440ffea 100644 (file)
@@ -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));
+    });
 });