簡體   English   中英

為什么它沒有從WeathermapAPI提醒我的信息

[英]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);

    });

});

URL查詢字符串中有很多空格。 刪除APPID之前的空格

注意:為了使下面的代碼片段起作用,我在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> 

更改這段代碼:

var api="http://api.openweathermap.org/data/2.5/weather?q=dehradun,india&           APPID=ab399c2f90228bbdabc65d72b81a1b4d";

至:

var api="http://api.openweathermap.org/data/2.5/weather?q=dehradun,india&APPID=ab399c2f90228bbdabc65d72b81a1b4d";

如果尚未添加,請將jquery CDN添加到您的html中。 嘗試這段代碼:

<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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM