问:重新检查了参数和变量之间的拼写,它看起来不错。我唯一想更改的就是在Doc.ready函数中我称他为AJAX请求的位置,但是怀疑这会有所不同。我肯定我缺少明显的东西。
谢谢!
weather.js
$ (文档)。准备好(函数() {
var weatherAPI = 'http : //api.openweathermap.org/data/2.5/weather ' ; var data = { q :“ Portland,OR” ,单位:“ metric” };函数showWeather (weatherReport ){ $ ('#temperature' )。文本(weatherReport 。主。临时); }; $ 。的getJSON
(weatherAPI , data , showWeather (weatherReport ));
});
index.html
<!DOCTYPE html>
< html >
< head >
< meta charset = “ utf-8” > < title >天气如何?</ title > < script src = “ jquery.js” > </ script > < script src = “ weather.js” > </ script > </ head > < body > < div id = “ main”
当前温度:< span id = “ temperature” > </ span > &deg; </ h1 >
</ div > </ body > </ html >
答:我认为您不需要将参数传递给showWeather函数。
$ 。getJSON (weatherAPI , data , showWeather );