类似于this question,我正在尝试从JS调用Java + Kotlin Spring Boot REST服务。
但是,我使用fetch函数代替XMLHttpRequest:
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()和getOnBackendRejected()已定义。
调用sendGetCountriesRequestToBackend()后,出现SyntaxError:输入意外结束
我想提取函数的参数有问题。有什么想法可以改变它们吗?