ノードjsファイルでjqueryを使用しようとしています。jquery モジュールは既にインストールされています。
ページにアクセスすると、次のエラーが表示されます。
var jqxhr = jquery.$.getJSON( "favs.json", function() {
^
TypeError: Cannot call method 'getJSON' of undefined
at Server.<anonymous>
at Server.EventEmitter.emit (events.js:98:17)
at HTTPParser.parser.onIncoming (http.js:2076:12)
at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:120:23)
at Socket.socket.ondata (http.js:1966:22)
at TCP.onread (net.js:525:27)
コード:
var http = require('http');
var jquery = require('jquery');
var PORT = 3000;
http.createServer(function(request, response) {
response.writeHead(200, {'Content-Type': 'text/plain', 'Access-Control-Allow-Origin': "*"});
var jqxhr = jquery.$.getJSON( "favs.json", function() {
console.log( "success" );
})
.done(function() {
console.log( "second success" );
})
.fail(function() {
console.log( "error" );
})
.always(function() {
console.log( "complete" );
});
}).listen(PORT);
console.log('Server running at http://127.0.0.1:' + PORT + '/');
これを修正する方法を知っている人はいますか?
ありがとう。