jquery simpleweather not recognized
我想使用simpleweatherjs在我的网站上显示天气,但它不适用于我。有人可以告诉我我做错了什么吗?页面是空白的。如果我,例如行$ .simpleWeather({...});放$(“#weather”).html(“test”),那么这个语句可以工作,但它不在$ .simpleWeather({...})下工作。就像它在示例中所示。jquery simpleweather not recognized
这里是我的html:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Weather</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery.simpleWeather/2.5.0/jquery.simpleWeather.min.js"></script>
</head>
<body>
<div id="weather"></div>
<script>
// Docs at http://simpleweatherjs.com
$(document).ready(function() {
$.simpleWeather({
location: 'Austin, TX',
woeid: '',
unit: 'f',
success: function(weather) {
html = '<h2><i class="icon-'+weather.code+'"></i> '+weather.temp+'°'+weather.units.temp+'</h2>';
html += '<ul><li>'+weather.city+', '+weather.region+'</li>';
html += '<li class="currently">'+weather.currently+'</li>';
html += '<li>'+weather.wind.direction+' '+weather.wind.speed+' '+weather.units.speed+'</li></ul>';
$("#weather").html(html);
},
error: function(error) {
$("#weather").html('<p>'+error+'</p>');
}
});
});
</script>
</body>
是否运行从本地文件的代码?即在浏览器中导航到c:\ html \ test.html(或同等版本)。
当为我做这件事时,它似乎没有工作,但是当我在网络服务器上托管HTML文件(我使用tomcat)并导航到http://localhost:8080/html/test/html
时,它工作正常。
编辑:这可以解释为什么它JS提琴正常工作以及
谢谢。当我上传文件到服务器,然后一切正常,但如果我在浏览器上打开文件,然后它不起作用。再次感谢提示。 – repincln
我托管我的文件,并得到相同的错误。 –
尝试清除您的线路:
<link rel="stylesheet" type="text/css" href="style.css">
也许有一些隐藏设置在那里。
和/或更改线路:(如果你是本地)
//query.yahooapis.com/v1/public/yql
到
http://query.yahooapis.com/v1/public/yql
控制台错误说,这是无法加载
//query.yahooapis.com/v1/public/yql.....
因此前缀HTTP或HTTPS链接像
https://query.yahooapis.com/v1/public/yql.....
检查您的控制台是否有错误。 – Andy
和控制台错误?因为它运作良好http://jsfiddle.net/yashhy/x34eu/在这里。 – yashhy
控制台:无法加载资源:net :: ERR_FILE_NOT_FOUND file://query.yahooapis.com/v1/public/yql?format = json&rnd = 20141114&diagnosti ... 2Austin,%20TX%22%20and%20gflags =%22R%22) %20and%20u =%22f%22&_ = 1393249498897 – repincln