$(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. Remove the blank spaces before APPID
Note: To make the below code snippet to work, I used https
in the API URL because StackOverflow uses https
protocol.
$(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. 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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.