I am a newbie and I can’t understand why my request is not sent. I wrote a function, JSON is created, but when sending, an error falls and the request does not reach the server. I see that 2 requests are sent, apparently to different places and with different answers. Backand server is launched
<script>
function submitData() {
// Get form data
const firstName = document.getElementById("firstName").value;
const lastName = document.getElementById("lastName").value;
// Construct JSON data
const data = JSON.stringify({
firstName: firstName,
lastName: lastName
});
// Send data to server
fetch("http://localhost:9001/client/create", {
method: "POST",
// mode: "no-cors",
headers: {
"Content-Type": "application/json"
},
body: data
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
}
</script>