S
S
Space2014-03-07 11:52:55
JavaScript
Space, 2014-03-07 11:52:55

How to clear data in nodeJS?

Hello. Here is a script for transmitting data over a socket.

var socket = io.connect( 'http://localhost:8080' );
$( "#messageForm" ).submit( function() {
  var nameVal = $( "#nameInput" ).val();
  var msg = $( "#messageInput" ).val();
  var canalVal = $( "#canalInput" ).val();
  if((nameVal) && (msg)){
  socket.emit( 'message', { name: nameVal, message: msg, canal: canalVal } )};
  
  // Ajax call for saving datas
  $.ajax({
    url: "./ajax/insertNewMessage.php",
    type: "POST",
    data: { name: nameVal, message: msg, canal: canalVal },
    success: function(data) {
      
    }
  });
  
  return false;
});

socket.on( 'message', function( data ) {
  var actualContent = $( "#messages" ).html();
  var newMsgContent = '<li> <strong>' + data.name + '</strong> : ' + data.message
                                          .replace(new RegExp("&#D83DDE04",'gi'),"<img src='../packs/basic/D83DDE04.png' height='20' width='20'>")
                                                                          .replace(new RegExp("&#D83DDC8A",'gi'),"<img src='../packs/basic/D83DDC8A.png' height='20' width='20'>") + '</li>';
  var content = newMsgContent + actualContent;
  
  $( "#messages" ).html( content );
});

As I understand it, the penultimate line $( "#messages" ).html( content );stores data that will be replaced on the next request. If I understood correctly, then how do I clean it up? Or explain, please, what's what. Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Space, 2014-03-07
@ruslite

as understood the message data is stored in data.message. how to clean?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question