2013-07-19 47 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