我正在创建一个使用https://restcountries.eu/ API的网络应用程序。
当用户输入国家/地区时,我将使用fetch. 但是,我的请求总是被取消。
我测试了捕获用户输入的部分,但我认为问题出在我的fetch代码上。
var countryName; // This will receive the user input on a textbox in my HTML file.
var resultado;
function grabCountry(urlendpoint, countryName, endpointfields) {
countryName = document.getElementById('searchInput').value;
var urlendpoint = 'https://restcountries.eu/rest/v2/name/';
var endpointfields = '?fields=topLevelDomain;alpha3Code;callingCodes;altSpellings;subregion;population;latlng;languages;flag';
fetch(urlendpoint + countryName + endpointfields)
.then(response => data)
.then(data => {
console.log(data())
})
}Run Code Online (Sandbox Code Playgroud)

