【发布时间】:2014-08-05 13:50:59
【问题描述】:
我让 node.js 与 jQuery 和这个插件一起工作:http://simpleweatherjs.com/。现在我想将天气数据用于另一个服务,而不是将其放入 HTML,但我无法访问/打印数据。错误函数有效,成功函数无效。
var jsdom = require("jsdom");
jsdom.env({
html: '<html><body><div id="weather"></div></body></html>',
scripts: [
'http://code.jquery.com/jquery-2.1.1.min.js',
'http://cdnjs.cloudflare.com/ajax/libs/jquery.simpleWeather/3.0.2/jquery.simpleWeather.min.js'
],
done: function(errors, window) {
var $ = window.jQuery;
$.simpleWeather({
location: 'Paris',
woeid: '615702',
unit: 'c',
success: function(weather) {
console.log(weather.temp+'°'+weather.units.temp);
},
error: function(error) {
console.log(error.message);
}
});
}
});
这就是它正常的样子http://codepen.io/fleeting/pen/xwpar
插件也有一个节点模块,但我不知道如何让它工作,也没有文档。
【问题讨论】:
标签: javascript jquery node.js yahoo weather