0

node.js から ajax を介してデータを受信しようとしていますが、2 つのやり取りの間で何が間違っているのかわかりません。

ここに私の 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 ドキュメントをポップアップ表示しています...そしてその下の行は実際には正しく機能します。通知を接続しようとしています (サーバー側で正しいデータが出力されます)。

4

1 に答える 1

0

わかりました、私は res.send としてそれをやっていました。それは res.json でなければなりません...

于 2013-08-06T04:42:14.343 に答える