JavaScript无法显示天气

JavaScript无法显示天气,javascript,coffeescript,Javascript,Coffeescript,我使用的是JSFIDLE——我将CSS、JavaScript和HTML放在一个文件中,并使用WampServer运行它。没有显示任何天气信息。我仔细检查了一切,但没有发现问题。有什么建议吗 代码: <!DOCTYPE html> <html> <head> <style> .weatherModule { background:#f2f2f2; height:150px; width:250px; border:

我使用的是JSFIDLE——我将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>

.天气模块{
背景#f2f2;
高度:150像素;
宽度:250px;
边框:1px虚线#ccc;
填充:1em;
}
.当前情况{
浮动:左;
}
.天气模块{
填充:1em;
}
.currentIcon{
浮动:左;
边缘:0.75em;
}
显示天气(){
$.ajax
网址:'http://api.wunderground.com/api/36b799dc821d5836/conditions/q/PA/Horsham.json'
数据类型:“jsonp”
数据:“url”
成功:(数据)->
对于索引,是数据的结果
temp=数学圆整结果temp\u f
icon=result.icon\u url
天气
$('p.currentConditions').html“当前#{temp}°;F和#{weather}”
$('div.currentIcon').html“”
}

显示天气
尝试添加

crossDomain: true,

你的$.ajax选项。

你的小提琴适合我。
$.ajax({[parameters]})Javascript控制台中有错误吗?@u_mulder这是coffeescript,你漏掉了很多括号。@Sumurai8他是这么说的:它在JSFIDLE中工作,而不是在他的真实站点上。这只在向同一来源发出请求并重定向到不同来源时才起作用。没有任何迹象表明这里正在发生这种情况。