getJSON没有输出?

时间:2012-05-09 15:02:21

标签: javascript jquery json api weather-api

我不能为我的生活弄清楚为什么这不起作用?

<div class="clouds">

</div>

<div class="station">

</div>

<script type="text/javascript">
$.getJSON("http://api.geonames.org/findNearByWeatherJSON?lat=53.36652&lng=-2.29855&username=jolones&callback=?",
function(data){

          var clouds = data.weatherObservation.clouds;
          var station = data.weatherObservation.stationName;

      jQuery.(".clouds").html(clouds);
      jQuery.(".station").html(station);

      });

非常欣赏

2 个答案:

答案 0 :(得分:3)

jQuery . (".clouds").html(clouds);
jQuery . (".station").html(station);

你的意思是在那里有那些点吗?应该是

jQuery(".clouds").html(clouds);
jQuery(".station").html(station);

答案 1 :(得分:0)

浏览器安全策略阻止您将json(xmlhttpReqeusts)转换为其他域。您应该查找JSONP的工作方式,如果geonames.org提供了jsonp方法(jsonp允许您执行此操作并调用另一个域),这可能很有用。

另一种选择是创建一个远程调用api的本地php脚本。 PHP不被禁止调用远程api,因此你可以使用php来检索json结果,然后使用javascript从你的本地(在同一域名)php程序中检索结果。

相关问题