当我通过单击按钮调用邮政编码时,我的函数应该将邮政编码放入openweathermap链接中,但它不起作用。我尝试了很多,但结果仍然相同。
const generateWeatherFunc = () => {
getWeatherInfo(OWMURL, zip, APINum)
.then( data =>{
postData('/data', {temperature: data.main.temp, date: newDate, feelings: feelings});
updateUserInterface('/info') } )
}
const getWeatherInfo = async (url, zipNum, apiId) => {
const res = await fetch(`${url}${zipNum}&appid=${apiId}`)
try {
const data = await res.json();
return data;
} catch(error) {
console.error(`error: ${error}`)
}
}
const postData = async (url='', data={}) => {
const res = await fetch(url, {
method: 'POST',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
try {
const _data = await res.json();
return _data;
} catch (error) {
console.error(`error: ${error}`)
}
}
我认为是因为当我单击“生成”按钮时,它不会发送任何数据
github中的完整代码:https://github.com/BasemAmr/Udacity-Weather-Journal-App-FEND/blob/master/website/app.js并运行它:安装模块:express, body-parser, cors
由npm install module_name
在终端中, node server.js
如果要在终端中运行本地主机端口5050