0

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>

enter image description here enter image description here

  • 4
    *"an error falls"* - What is the error? Relevant code and error messages need to be included in your question *as text*, [not as pictures of text](https://meta.stackoverflow.com/q/285551/328193). Just linking to screen shots makes it more difficult for people to help you. To learn more about this community and how we can help you, please start with the [tour] and read [ask] and its linked resources. – David Feb 22 '23 at 21:31

0 Answers0