Skip to content
Snippets Groups Projects
Commit b7b659f6 authored by romain's avatar romain
Browse files

ajout fetch

parent c8c22523
No related branches found
No related tags found
No related merge requests found
......@@ -50,8 +50,8 @@
<body>
<h1> OUCÉQUECÉ</h1>
<h2>Quel est ton nom ?</h2>
<h3><form action="/submit-name" method="post">
<input type="text" id="nom" name="nom" required>
<h3><form action="Front.html" method="post">
<input type="text" id="nom" name="name" required>
<br>
<button type="submit">Envoyer</button>
</form></h3>
......@@ -65,4 +65,37 @@
</div>
</body>
<script>
document.getElementById('nom').addEventListener('submit', function(event) {
event.preventDefault();
const name = document.getElementById('name').value;
const jsonData = {
username: name
};
fetch('https://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.');
});
});
</script>
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "localhost:8080/projet_prog_reseau_war_exploded/api/start");
curl_exec($ch);
curl_close($ch);
?>
</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