-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,218
  • 1
  • 4
  • 17
SlandShow
  • 252
  • 1
  • 9

2 Answers2

0

Here, You have to specify the full URL.

...
let response = await fetch("http://localhost:8080/url-shortenerer/create", {
...
Devendra
  • 55
  • 1
  • 10
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
});
lafleur
  • 107
  • 8