0

我正在使用 JSFiddle示例- 我已将 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} &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>
4

1 回答 1

-1

尝试添加

crossDomain: true,

到您的 $.ajax 选项。

于 2013-07-19T19:22:36.643 回答