– akeeseth May 27 '13 at 11:27

2 Answers2

0

Your message is being parsed as HTML. You can either escape the HTML entities on the server (depending on your server side language, but preferred regardless), or you can use text nodes to set the textContent of the message, rather than HTML;

var markup = $(jQuery.parseHTML('<div class="message"><span class="userName"></span></div'));

markup.find('.userName').text(fromUserName);
markup.append(document.createTextNode(message));

$('#' + ctrId).find('#divMessage').append(markup);

... but just to emphasize, you should really be encoding this on the server.

Matt
  • 74,352
  • 26
  • 153
  • 180
-1

First look at google results would show You the answer.

var url = "your script url";
var message = document.createElement('script');
message.type = 'text/javascript';
message.src = url;
$('#' + ctrId).find('#divMessage').append('<div class="message"><span class="userName">' + fromUserName + '</span>: ' + message + '</div>');

http://mg.to/2006/01/25/json-for-jquery

Can't append <script> element

Can I create script tag by jQuery?

Community
  • 1
  • 1
Kamil T
  • 2,232
  • 1
  • 19
  • 26
  • I don't understand why my answer got a downvote. It fixes the problem and I don't find it vulgar or anything... – Kamil T May 27 '13 at 11:41