[英]why it's not alerting my information from WeathermapAPI
$(document).ready(function(){
var api="http://api.openweathermap.org/data/2.5/weather?q=dehradun,india& APPID=ab399c2f90228bbdabc65d72b81a1b4d";
$.getJSON(api,function(data){
alert(data.coord.lat);
});
});
There is lot of spaces in the URL query strings. URL查询字符串中有很多空格。 Remove the blank spaces before
APPID
删除
APPID
之前的空格
Note: To make the below code snippet to work, I used https
in the API URL because StackOverflow uses https
protocol. 注意:为了使下面的代码片段起作用,我在API URL中使用了
https
,因为StackOverflow使用https
协议。
$(document).ready(function(){ var api="https://api.openweathermap.org/data/2.5/weather?q=dehradun,india&APPID=ab399c2f90228bbdabc65d72b81a1b4d";; $.getJSON(api,function(data){ alert(data.coord.lat); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Change this piece of code: 更改这段代码:
var api="http://api.openweathermap.org/data/2.5/weather?q=dehradun,india& APPID=ab399c2f90228bbdabc65d72b81a1b4d";
to: 至:
var api="http://api.openweathermap.org/data/2.5/weather?q=dehradun,india&APPID=ab399c2f90228bbdabc65d72b81a1b4d";
Please add the jquery cdn to your html if you haven't added it. 如果尚未添加,请将jquery CDN添加到您的html中。 Try this piece of code:
尝试这段代码:
<script
src="https://code.jquery.com/jquery-3.3.0.min.js"
integrity="sha256-RTQy8VOmNlT6b2PIRur37p6JEBZUE7o8wPgMvu18MC4="
crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
var api="http://api.openweathermap.org/data/2.5/weather?q=dehradun,india&APPID=ab399c2f90228bbdabc65d72b81a1b4d";
$.getJSON(api,function(data){
alert(data.coord.lat);
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.