Javascript response.json是未定义的express.js
下面是我目前的代码:Javascript response.json是未定义的express.js,javascript,node.js,express,undefined,backend,Javascript,Node.js,Express,Undefined,Backend,下面是我目前的代码: function geoPerformAction(e) { getGeoApiData(document.getElementById('zipPostCode').value) .then((APIarr) => { postGeoData('/geoadd', { Lat: APIarr[0] }); }) .then(function () { updateUIGeo(); }) } //F
function geoPerformAction(e) {
getGeoApiData(document.getElementById('zipPostCode').value)
.then((APIarr) => {
postGeoData('/geoadd', { Lat: APIarr[0] });
})
.then(function () {
updateUIGeo();
})
}
//Friend helped with me with get API data
/* Function to GET Web API Data*/
const getGeoApiData = async ( place) => {
const response = await fetch("https://pokeapi.co/api/v2/pokemon/" + place + "/");
try {
const webData = response.json();
const Pla = webData;
console.log(Pla);
const APIarr = [Pla];
return APIarr;
}
catch (error) {
console.log("error", error);
}
}
每次我使用它时,webdata变量都是未定义的。为什么会这样?为什么不返回我请求的数据
谢谢。您不是在等待第二个承诺得到解决
const webData = await response.json();
例如:
async function fetchAsync () {
// await response of fetch call
const response = await fetch('https://api.github.com');
// only proceed once promise is resolved
const data = await response.json();
// only proceed once second promise is resolved
return data;
}