-1

For example, I have some basic form:

var formElem = document.getElementById("some_basic_form");
formElem.onsubmit = async(e) => {
  e.preventDefault();

  let fullUrl = document.getElementById('shorten_url').value
  let formData = new FormData();
  formData.append('fullUrl', fullUrl);

  let response = await fetch('/url-shortenerer/create', {
    method: 'POST',
    body: formData
  });

  let result = await response.json();

  alert(result.message);
};
<form action="http://localhost:8080" method="post" id="some_basic_form">
  Full url: <input id="shorten_url">
  <input type="submit">
</form>
I want to send a POST request to the backend service, but I see, that request sent via 63342 port, not 8080. How to solve it?
Daweed
  • 1,419
  • 1
  • 9
  • 24
SlandShow
  • 443
  • 3
  • 13

1 Answers1

0

I think providing the mode property with the init object will fix the CORS errors.

let response = await fetch("http://localhost:8080/url-shortenerer/create", { 
    mode: 'cors',
    method: 'POST',
    body: formData
});
floreapaun
  • 124
  • 10