javascript - 在node js服务器端添加jquery : Specifically using $. getJSON在nodeJS上不起作用

标签 javascript jquery ajax node.js getjson

我正在尝试在我的 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/

相关文章:

javascript - 在点击时制作一些彩色瓷砖打开一个div

c# - Azure 中的 PRM_ServerError,在模拟器中正确运行

javascript - 如何将 html 表格以多选项卡格式导出到 Excel?

javascript - 线性+阈值统一尺度

javascript - 模拟服务返回对象($$state)错误

javascript - ExternalInterface addCallback 多次失败

javascript - 单击鼠标中键停止打开新选项卡

php - 即使我重定向到另一个 URL,我也需要保持 PHP 进程在后台运行

javascript - 将附加元素附加并保留到 jQuery ui-autocomplete

javascript - Chrome 上的 will-change 问题