我正在尝试在我的 server.js 上添加 Jquery。我使用 Windows 8 作为我的服务器。我正在使用 Node.js 上的 jquery 执行 AJAX 调用。 我的服务器实际上会从 YAHOO 加载 JSON 数据。我得到了端口 5555
我运行命令提示符并输入
npm install jquery
然后:
node server.js
这是我的 server.js
var $ = require('jquery');
var http = require("http")
, fs = require("fs")
, qs = require("querystring")
, port = 5555
var server = http.createServer(function(request, response) {
$.getJSON( 'http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.historicaldata where symbol = 'AAL'&format=jsonstore://datatables.org/alltableswithkeys
', cbFunc);
});
function cbFunc(data){
console.log(data);
}
server.listen(port);
console.log('Server is listening to http://localhost/ on port ' + port + '...');
任何人都可以帮助我解决我的问题。提前致谢!
请忽略该 URL,因为这只是一个示例,它适用于我的 YAHOO URL
最佳答案
npm 安装请求
然后:
var request = require('request');
request.get(myUrl, { json: true }, function(err, res) {
// handle res data here
})
关于javascript - 在node js服务器端添加jquery : Specifically using $. getJSON在nodeJS上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30496011/