如何为 Javascript 使用 OpenWeatherMap API?
How to use OpenWeatherMap API for Javascript?
我正在尝试使用 OpenWeatherMap API 为 javascript 创建一个天气应用程序。我的网络应用程序的代码是:
<!DOCTYPE html>
<html>
<head>
<title>Weather</title>
<script src = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.min.js"></script>
<script>
function gettingJSON(){
document.write("jquery loaded");
$.getJSON("api.openweathermap.org/data/2.5/weather?q=London&APPID=ee6596241130f193adf1ba90e625cc10",function(json){
document.write(json);
}
</script>
</head>
<body>
<button id = "getIt" onclick = "gettingJSON()">Get JSON</button>
</body>
</html>
我哪里错了?
您尚未完成 parenthesis
getJSON
方法。除此之外,我对你的代码做了一些修改。
<!DOCTYPE html>
<html>
<head>
<title>Weather</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
function gettingJSON(){
document.write("jquery loaded");
$.getJSON("http://api.openweathermap.org/data/2.5/weather?q=London&APPID=ee6596241130f193adf1ba90e625cc10",function(json){
document.write(JSON.stringify(json));
});
}
</script>
</head>
<body>
<button id = "getIt" onclick = "gettingJSON()">Get JSON</button>
</body>
</html>
我正在尝试使用 OpenWeatherMap API 为 javascript 创建一个天气应用程序。我的网络应用程序的代码是:
<!DOCTYPE html>
<html>
<head>
<title>Weather</title>
<script src = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.min.js"></script>
<script>
function gettingJSON(){
document.write("jquery loaded");
$.getJSON("api.openweathermap.org/data/2.5/weather?q=London&APPID=ee6596241130f193adf1ba90e625cc10",function(json){
document.write(json);
}
</script>
</head>
<body>
<button id = "getIt" onclick = "gettingJSON()">Get JSON</button>
</body>
</html>
我哪里错了?
您尚未完成 parenthesis
getJSON
方法。除此之外,我对你的代码做了一些修改。
<!DOCTYPE html>
<html>
<head>
<title>Weather</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
function gettingJSON(){
document.write("jquery loaded");
$.getJSON("http://api.openweathermap.org/data/2.5/weather?q=London&APPID=ee6596241130f193adf1ba90e625cc10",function(json){
document.write(JSON.stringify(json));
});
}
</script>
</head>
<body>
<button id = "getIt" onclick = "gettingJSON()">Get JSON</button>
</body>
</html>