我正在使用JSFiddle example - 我已将CSS,JavaScript和HTML放在一个文件中,并且正在使用WampServer来运行它。没有显示天气信息。我仔细检查了一切,但找不到问题。有什么建议吗?
代码:
<!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} ° 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 :(得分:-1)
尝试添加
crossDomain: true,
到$ .ajax选项。