小编Mar*_*ves的帖子

我的提取请求被取消,我不知道为什么

我正在创建一个使用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)

IMAGE:我总是在网络中收到此错误

IMAGE:控制台中的这个错误

javascript fetch

5
推荐指数
2
解决办法
303
查看次数

标签 统计

fetch ×1

javascript ×1