0
Guys, I’m developing a chat room with Faye. Back-end normal. Fucionando perfectly, but I have silly problem: I can not insert the messages for viewing. I will explain better:
When I retrieve the messages I insert it into a <div class="panel_msg>
, inside a table (I know it’s not the most viable alternative, but it’s just a test). Hence using the function html()
he jQuery he does the job normally, but when another client sends a message he doesn’t add another table in the div, he just adds the text next to the existing text.
How do I go adding 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>
<script type="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, the way I recover is correct?
I think you need to use the
.append()
but without seeing your code I can’t say for sure. Add the code to the question so we can help more...– Sergio
Post the code
html
andjquery
to facilitate friendly understanding.– Jhonatan Simões