-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate.js
More file actions
28 lines (22 loc) · 869 Bytes
/
Copy pathCreate.js
File metadata and controls
28 lines (22 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const token = localStorage.getItem("token");
async function postproduct() {
let name = document.getElementById("nom").value;
let categoryId = document.getElementById("categorie").value;
const response = await fetch("http://localhost:3000/produits", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
name: name,
categoryId: Number.parseInt(categoryId),
}),
});
const data = await response.json();
console.log("Connexion réussie:", data);
document.getElementById("success").innerHTML = "SUCCESS";
document.getElementById("categorie").value = "";
document.getElementById("nom").value = "";
}
document.getElementById("submit").addEventListener("click", postproduct);