Actualiser test.html
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
This commit is contained in:
@@ -36,21 +36,23 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 2. Charger les produits via l'action correcte
|
// 2. Charger les produits
|
||||||
fetch('api/index.php?action=products_list')
|
fetch('api/index.php?action=products_list')
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
console.log("DEBUG PRODUITS :", data); // Ouvre la console F12 pour voir ça !
|
||||||
const sel = document.getElementById('product-selector');
|
const sel = document.getElementById('product-selector');
|
||||||
// On utilise 'data' directement si c'est un tableau, ou la clé correcte
|
|
||||||
const prods = data.products || data;
|
const prods = data.products || data;
|
||||||
prods.forEach(p => {
|
if(Array.isArray(prods)) {
|
||||||
const opt = document.createElement('option');
|
prods.forEach(p => {
|
||||||
opt.value = p.id;
|
const opt = document.createElement('option');
|
||||||
opt.setAttribute('data-name', p.name);
|
opt.value = p.id;
|
||||||
opt.setAttribute('data-cat', p.category || '');
|
opt.setAttribute('data-name', p.name);
|
||||||
opt.textContent = p.name;
|
opt.setAttribute('data-cat', p.category || '');
|
||||||
sel.appendChild(opt);
|
opt.textContent = p.name;
|
||||||
});
|
sel.appendChild(opt);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function updateIdField() {
|
function updateIdField() {
|
||||||
@@ -61,6 +63,7 @@
|
|||||||
document.getElementById('category-selector').value = opt.getAttribute('data-cat');
|
document.getElementById('category-selector').value = opt.getAttribute('data-cat');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3. Fonction unique de sauvegarde
|
||||||
function saveProduct() {
|
function saveProduct() {
|
||||||
const data = {
|
const data = {
|
||||||
id: document.getElementById('prod-id').value,
|
id: document.getElementById('prod-id').value,
|
||||||
@@ -68,8 +71,6 @@
|
|||||||
category: document.getElementById('category-selector').value
|
category: document.getElementById('category-selector').value
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("Données envoyées :", data); // Vérifie ceci dans ta console F12
|
|
||||||
|
|
||||||
fetch('api/index.php?action=product_save', {
|
fetch('api/index.php?action=product_save', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
@@ -77,22 +78,10 @@
|
|||||||
})
|
})
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(res => {
|
.then(res => {
|
||||||
// Affiche tout l'objet de réponse pour voir le message d'erreur précis
|
console.log("RÉPONSE API :", res);
|
||||||
console.log("RÉPONSE COMPLÈTE DE L'API :", res);
|
alert("Réponse reçue. Regarde la console (F12) pour le détail.");
|
||||||
alert("Réponse reçue (voir console F12) : " + JSON.stringify(res));
|
|
||||||
})
|
})
|
||||||
.catch(e => console.error("Erreur réseau :", e));
|
.catch(e => console.error("Erreur :", e));
|
||||||
}
|
|
||||||
|
|
||||||
// On utilise l'action 'product_save' identifiée par ton grep
|
|
||||||
fetch('api/index.php?action=product_save', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {'Content-Type': 'application/json'},
|
|
||||||
body: JSON.stringify(data)
|
|
||||||
})
|
|
||||||
.then(r => r.json())
|
|
||||||
.then(res => alert("Réponse API : " + JSON.stringify(res)))
|
|
||||||
.catch(e => alert("Erreur : " + e));
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user