Javascript 节点JS和ajax问题

Javascript 节点JS和ajax问题,javascript,jquery,node.js,notifications,Javascript,Jquery,Node.js,Notifications,我试图通过ajax从node.js接收数据,但我不确定在这两者之间的交互中我做错了什么 以下是我的ajax get请求: $.get('/notificationsNumber', function (notify) { alert(notify); $('.notifications').html("Notifications " + 0).css("color","red") }); 这是我的node.js

我试图通过ajax从node.js接收数据,但我不确定在这两者之间的交互中我做错了什么

以下是我的ajax get请求:

$.get('/notificationsNumber',  
        function (notify) {
            alert(notify);
            $('.notifications').html("Notifications " + 0).css("color","red")

    });   
这是我的node.js文件:

exports.notificationsNumber = function(req, res) {
    console.log('notifying start');
    Friend.findOne({userId: req.signedCookies.userid}, function(err,user) {
        if(err) {
            res.send(err);
            console.log('notifying err');
        } else {
            console.log('notifying');
            console.log(user.notifications);
            var notify = user.notifications;
            console.log(notify);
            res.send(notify);
        }
    });
};
更新:

app.get('/notificationsNumber', user.notificationsNumber);
下面是app.js代码:


由于某种原因,警报会弹出页面的html文档。。。它下面的线实际上工作正常。尝试连接notify(服务器端的notify打印出正确的数据)。

好的,我是以res.send的身份执行的,应该是res.json…

到底是什么问题?数据没有显示(notify)在ajax调用中,您能否显示向服务器上的路由器添加
notificationsNumber
的代码?您是指路由器文件,因为我将其包含在脚本文件的正下方?如果在我添加app.js文件时您正在谈论它,它会破坏警报以及所有应该是app.get('/notificationsNumber',exports.notificationsNumber)的内容