2013-07-19 51 views
0

我正在使用JSFiddle example - 我将CSS,JavaScript和HTML放在一个文件中,并且正在使用WampServer来运行它。没有显示天气信息。我仔细检查了一切,但找不到问题。有什么建议么?JavaScript无法显示天气

代码:

<!DOCTYPE html> 
<html> 
<head> 

<style> 
.weatherModule { 
    background:#f2f2f2; 
    height:150px; 
    width:250px; 
    border: 1px dashed #ccc; 
    padding: 1em; 
} 
.currentConditions { 
    float: left; 
} 
.weatherModule { 
    padding: 1em; 
} 

.currentIcon { 
    float: left; 
    margin: 0 .75em; 
} 

</style> 

<script type="text/javascript"> 

displayWeather(){ 

$.ajax 
    url: 'http://api.wunderground.com/api/36b799dc821d5836/conditions/q/PA/Horsham.json' 
    dataType: 'jsonp' 
    data: 'url' 
    success: (data) -> 
     for index, result of data 
       temp = Math.round result.temp_f 
       icon = result.icon_url 
       weather = result.weather 
       $('p.currentConditions').html "Currently #{temp} &deg; F and #{weather}" 
       $('div.currentIcon').html "<img src='#{icon}' >" 

} 
</script> 
</head> 
<body> 
<div class="weatherModule"> 
<p class="currentConditions"></p> 
<div class="currentIcon"></div> 
</div> 
<form> 
<button type="button" onclick="displayWeather()">Display Weather</button> 
</form> 
</body> 
</html> 
+0

你的小提琴适合我。 – Sumurai8

+1

'$ .ajax({[parameters]});' –

+0

Javascript控制台中的任何错误? – Barmar

回答

-1

尝试增加

crossDomain: true, 

到$阿贾克斯选项。

+0

只有在向*相同原点*发出**重定向**到不同原点的请求时才有效。没有任何迹象表明这是发生在这里。 – Quentin