Good afternoon, there was a problem, there is a block in the admin panel, with live output of new messages from the history on jquery

The response from the server is formed as follows:

for ($i=0;$i<$c;$i++) { $msg .= $icq[$i]['uid'].'>> '. $icq[$i]['msg'].'<br>'; } echo $msg; 

inserting a response into a block occurs every 3 seconds with the following code:

 function go() { var count = document.getElementById("box"); if(count != null) $.ajax({ url: 'http://site.ru/api/', success: function(data) { $("#box").text(data); } }); 

setTimeout (go, 3000); }

var update = go ();

The problem is as follows: each new message from the history was planned to be output from a new line. To do this, at the end of each iteration of the loop, <br> is inserted into the response, but the messages are displayed as follows:

message 1 <br> message 2 <br> message3 <br>

Tell me how to remove <br> and make a normal line break?

  • one
    $("#box").html(data); - zb '
  • for transfer you can try not to insert <br/>, but \ n. - Skolozub

2 answers 2

http://jsfiddle.net/R6Kz7/1/

DOM Insertion, Inside

appendTo ()

  • Could you write how to use it? - Alexandr Vasilenko
  • one
    $("#box").append(data); only better make elements like <div> - zb '
  • one
    Updated post - do4a
  • Thanks, the top answer helped! - Alexandr Vasilenko

Try to change

 $("#box").text(data); 

on

 $("#box").html(data);