简体   繁体   English

单击按钮从外部获取天气数据时出现问题 API

[英]problem when clicking a button to fetch weather data from outside API

I have a weather app where i fetch data from outside API.. i have an input where i type a city name and get the weather info when clicking on search icon..the problem is, i have to refresh the page many times to get the data even after i type the city name and click the button.. i need to get the data once i type the city name and click the button..what is wrong with my code??.. i have 2 files linked in HTML page the first contain the request function我有一个天气应用程序,我在其中从 API 外部获取数据。我有一个输入,我在其中输入城市名称并在单击搜索图标时获取天气信息。问题是,我必须多次刷新页面才能获取即使在我输入城市名称并单击按钮后数据..一旦我输入城市名称并单击按钮,我需要获取数据..我的代码有什么问题??..我在 HTML 中有 2 个文件链接第一个页面包含请求 function 请求代码

the second one is the app.js file where i call the function from the first file第二个是 app.js 文件,我从第一个文件中调用 function 函数调用

Try putting the weather(inputValue, (error, weatherData)=>{});尝试把weather(inputValue, (error, weatherData)=>{}); inside the click event listener like this:在 click 事件侦听器中,如下所示:

search.addEventListener('click', ()=>{

weather(inputValue, (error, weatherData)=>{

//Do the rest here

});

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM