S
S
Space2014-03-07 14:52:28
JavaScript
Space, 2014-03-07 14:52:28

How to clear socket variable?

Hello. I recently raised this issue, but now I understand which variable needs to be cleared. here is the script:

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) {
      var msg = $( "#messageInput" ).html('');
    }
  });
  
  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='21' width='21'>")
   																              	.replace(new RegExp("&#D83DDC8A",'gi'),"<img src='../packs/basic/D83DDC8A.png' height='21' width='21'>") + '</li>';
  var content = newMsgContent + actualContent;
  
  $( "#messages" ).html( content );
  data.message.remove();
});

gotta clean it up data.message. Question: how?

Answer the question

In order to leave comments, you need to log in

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

Try
or
data.message = null;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question