我的 NodeJS 代碼。我在控制臺中得到正確的結果,但頁面未重定向到串列頁面
function displayCities(cname) {
var pageData = {
title: "Listings",
cities: null
};
axios(
//the request
{
url: "https://sandbox.repliers.io/listings?city=" cname,
method: "GET",
headers: {
'Content-Type': 'application/json',
'REPLIERS-API-KEY': 'SKoKOGhEO42QzdkZ1cowKgLGm2mwm4'
}
}
).then(function (response){
//on success do stuff
console.log(response.data);
pageData.cities = response.data; //store JSON results in pageData.cities (previously null)
res.render("listings", pageData);
}).catch(function (error){
console.log(error);
});
}
uj5u.com熱心網友回復:
您尚未將res物件傳遞給函式。
為了能夠訪問res物件的方法,您應該將其添加到函式簽名中,并將其提供給您呼叫它的函式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/449936.html
上一篇:shell腳本
