在节点 js 服务器端添加 jquery:特别是使用 $.getJSON 在 nodeJS 上不起作用
Adding jquery on nodejs Serverside: Specifically using $.getJSON won't work on nodeJS
我正在尝试在我的 server.js 上添加 Jquery。我正在使用 windows 8 作为我的服务器。我在 nodejs 上用 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
})
我正在尝试在我的 server.js 上添加 Jquery。我正在使用 windows 8 作为我的服务器。我在 nodejs 上用 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
})