R
R
ratatyq2016-04-24 20:39:04
JavaScript
ratatyq, 2016-04-24 20:39:04

Why does such an error pop up?

Hello, here I met with such a Jquery error for node js

TypeError: $.parseJSON is not a function

and I don’t understand why I included this library ....
Here is the code:
var WebSocketClient = require('websocket').client;
var $ = require('jquery');
var client = new WebSocketClient();

client.on('connect', function(connection) {
    console.log('WebSocket Client Connected');
    connection.on('error', function (error) {
        console.log("[ERROR]Connection Error: " + error.toString());
    });
    connection.on('close', function () {
        console.log('[WARNING] echo-protocol Connection Closed');
    });
    connection.on('message', function (message) {
        if (message.type === 'utf8') {
           console.log("Received: '" + message.utf8Data + "'");
           var string = message.utf8Data;
           var dannie = $.parseJSON(string);
           console.log(dannie.online);
        }
    });
});
client.connect('ws://node.csgohot.com:8083/', 'echo-protocol');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Shilka, 2016-04-24
@glitch536

Use JSON.parse(str)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question