0

Similar to this question I am trying to call a Java+Kotlin Spring Boot REST service from JS.

However instead of XMLHttpRequest, I use fetch function:

function sendGetCountriesRequestToBackend(port) {
const endpoint = "/countries";
const url = 'http://localhost:' + port + endpoint;

const arguments = {
    method: "GET",
    mode: "no-cors",
    cache: "no-cache",
    credentials: "omit",
    headers: {
        "Content-Type": "application/json"
    },
    redirect: "follow",
    referrer: "no-referrer"
};

fetch(url, arguments)
    .then(response => response.json())
    .then(getOnBackendFulfilled())
    .then(null, getOnBackendRejected());

 }

getOnBackendFulfilled() and getOnBackendRejected() are defined.

After calling sendGetCountriesRequestToBackend() I get SyntaxError: Unexpected end of input

I suppose there's something wrong with arguments for fetch functions. Any ideas how to change them?

Krzysztof
  • 129
  • 2
  • 11
  • You should check what setting the [`mode` to `no-cors`](https://developer.mozilla.org/en-US/docs/Web/API/Request/mode#Value) does and the consequences, ie unable to read the response – Patrick Evans Apr 27 '19 at 12:55
  • Thanks Patrick, I changed arguments to { method: "GET", headers: [ ["Content-Type", "application/json"], ["Content-Type", "text/plain"] ], credentials: "include" }; SAME ERROR :( – Krzysztof Apr 27 '19 at 13:48

0 Answers0