0

Here is what I have:

Client Side:

socket.on('PING__',function (data){
    console.log(data);
});
socket.emit('__PING');

Server Side:

io.sockets.on('connection', function (socket) {
    var connection = socket;
    socket.on('__PING', function (data) {
        console.log(data);
        socket.emit('PING__' , {status:'OK'});
    });
});

The console logs out "object {status:'OK'}". If I do this instead on the client:

console.log(data.status);

I get undefined. I don't understand why it isn't logging out the status portion of the JSO. Any help here would be great

4

1 回答 1

0

显然这是一个依赖于平台的问题。它发生在 Chromium 中,但不在 Firefox 中。我这样做了:

console.log($(data)[0].status);

它工作得很好。使用 jQuery 解决跨平台问题的另一个原因:-/

于 2012-11-26T18:31:05.447 回答