Well, I'm developing a Chat with Faye. On the back end everything is normal. Fucking perfectly, but I'm having a silly problem: I can not insert the messages for viewing. I'll explain better:
When I retrieve the messages I enter a <div class="panel_msg>
, inside a table (I know it's not the most viable alternative, but it's just a test). So by using the html()
function it jQuery does the job normally, but when another client sends a message it does not add another table in the div, it just adds the text next to the existing text.
How do I add table after table?
HTML
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<title>iCube • Beta</title>
<script type="text/javascript" src="http://localhost:8000/faye/client.js"></script><scripttype="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<!-- Carrega Styles css -->
<link href='https://fonts.googleapis.com/css?family=Roboto+Condensed' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" type="text/css" href="css/menu.css">
<link rel="stylesheet" type="text/css" href="css/campo_texto.css">
</head>
<body>
<!-- Menu -->
<div class="menu">
<ul>
<!-- Em breve -->
</ul>
</div>
<!-- Fim menu -->
<!-- Campo de texto -->
<div class="campo_texto">
<table cellspacing="10">
<tr>
<td><input type="text" id="texto"></td>
<td><button id="enviar">Enviar</button></td>
</tr>
</table>
</div>
<!-- Fim campo de texto -->
<div class="panel_msg">
<!-- As mensagens veem aqui -->
</div>
</body>
</html>
jQuery
var client = new Faye.Client('http://localhost:8000/faye');
$(function () {
$('#enviar').click(function(){
var mensagem = $('#texto').val();
client.publish('/faye', { 'texto': mensagem });
client.subscribe('/faye', function (message) {
$('.panel_msg').html("
<table cellspacing=\"12\" >
<tr>
<td class=\"msg_txt\">"+message.texto+"
</td>
</tr>
<table>");
});
$('.panel_msg').html("
<table cellspacing=\"12\" >
<tr>
<td class=\"msg_txt\">"+message.texto+"</td>
</tr>
</table>");
});
});
PS: I am sending a JSON there, how do I recover it is correct?