Skip to content
Snippets Groups Projects
Commit 872c4ec2 authored by AUCHET Romain's avatar AUCHET Romain
Browse files

modification transmission données json

parent 14bdfe12
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,7 @@
<body>
<h1> OUCÉQUECÉ</h1>
<h2>Quel est ton nom ?</h2>
<h3><form action="Front.html" method="post">
<h3><form action="home.html" method="post">
<input type="text" id="nom" name="name" required>
<br>
<button type="submit">Envoyer</button>
......@@ -66,30 +66,40 @@
</body>
<script>
document.getElementById('nom').addEventListener('submit', function(event) {
event.preventDefault();
document.getElementById('nom').addEventListener('submit', transmission() )
const name = document.getElementById('name').value;
const jsonData = {
"username": name
};
fetch('http://localhost:8080/projet_prog_reseau_war_exploded/api/start', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(jsonData)
})
.then(response => {
if (!response.ok) {
throw new Error("Erreur lors de l'envoi");
}
})
.catch(error => {
console.error('Erreur :', error);
alert('Une erreur est survenue lors de l’envoi.');
});
});
async function transmission() {
const Jsondata = {
username:name
};
try {
const response = await fetch("http://localhost:8080/projet_prog_reseau_war_exploded/api/start", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(Jsondata),
});
if (!response.ok) {
throw new Error(`Erreur HTTP : ${response.status}`);
}
const responsejson = await response.json();
localStorage.setItem("transferdata", JSON.stringify(responsejson));
window.location.href = "front.html";
} catch (error) {
console.error("Erreur : ", error);
document.getElementById("response").textContent = `Erreur : ${error.message}`;
}
}
</script>
</script>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment