D
D
durnevdanya2017-03-09 20:21:10
JavaScript
durnevdanya, 2017-03-09 20:21:10

Code instead of Node JS text?

There is a code for the client and the server, the application itself is like a chat, and so, if you send a message, then one code comes instead of text, what's the problem? qczl7HuQtP8.jpgclient

var socket = io();
    chat = document.querySelector("#chat");
    function sendMsg() {
      var msg = document.querySelector("#message").value;
      socket.emit('sendMessage', msg);

      socket.on('backMsg', function(data){
        chat.append('<div class="well">'+data+'</div>');
        data('');
      });
    }

server
socket.on('sendMessage', function(data){
    io.sockets.emit('backMsg', data);
  });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri, 2017-03-09
@durnevdanya

chat.append takes as input not html code as text, but domElement. that is, you need to do it through document.createElement(...)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question