简体   繁体   English

未捕获的 ReferenceError:未定义 findWeather

[英]Uncaught ReferenceError: findWeather is not defined

I am currently working on a simple web-app for my studies that shows the current weather per location and current weather on the location you type in. I have in my HTML file:我目前正在为我的研究开发一个简单的网络应用程序,该应用程序显示每个位置的当前天气和您输入的位置的当前天气。我的 HTML 文件中有:

<div id="data">
</div>
<input type="text" value="Which city are you in?">
<input type="button" value ="Submit" onclick="findWeather()">

and for the JavaScript file:对于 JavaScript 文件:

function findWeather() {
    $.get("http://api.openweathermap.org/data/2.5/forecast?q=Eindhoven&appid=*My_APP_ID*",
            function () {
                document.getElementById("data").innerHTML = data.list.main.temp;
            })
}

Of course I have filled in the right App ID, I'm just not sure whether to share it here or not.当然我已经填写了正确的App ID,只是不知道要不要在这里分享。

The JavaScript script won't run and I have no clue why. JavaScript 脚本无法运行,我不知道为什么。

EDIT: I seem to getUncaught ReferenceError: findWeather is not defined error, while I did declare findWeather..?编辑:我似乎 getUncaught ReferenceError: findWeather is not defined 错误,而我确实声明了 findWeather ..?

You haven't defined data .您尚未定义data

Presumably it is supposed to be the first argument of the function you pass as the second argument to $.get .据推测,它应该是您作为第二个参数传递给$.get的函数的第一个参数。

After passing the URL, as a second argument of the .get() function you are passing a callback anonymous function.传递 URL 后,作为 .get() 函数的第二个参数,您将传递回调匿名函数。 In this function you must declare the parameter in which the data should be stored.在此函数中,您必须声明应存储数据的参数。 For example:例如:

function findWeather(){
    $.get("http://api.openweathermap.org/data/2.5/forecast?q=Eindhoven&appid=*My_APP_ID*", 
           function(data) {
               document.getElementById("data").innerHTML = data.list.main.temp;
    })
}

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

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