1

I am writing a chat module. I sent the text to the database as HTML.

When I bring it to the server, the string has HTML (Mainly <br />). I use JQuery's .html() function to put the chat content on a div.

The problem is that the text loads but its not rendered as HTML. This is the function that sends the message and then returns the contents to the div. #send-message is a textbox:

        $('#send-message').bind("enterKey",function(e){
            $.ajax({
                type : 'POST',
                url : "<POST_URL>",
                async : false,
                data: { 'message' : $("#send-message").val() },
                beforeSend: function (request) {
                    request.setRequestHeader("X-CSRFToken",
                    $('input[name="csrfmiddlewaretoken"]').val());
                },
                success : function (returnData) {
                    $( "#conversation" ).html( returnData );
                },
                error : function (xhr, textStatus, errorThrown) {
                     //other stuff
                },
                complete : function (){
                }
            });
        }); 
        $('#send-message').keyup(function(e){
            if(e.keyCode == 13)
            {
            $(this).trigger("enterKey");
            }
        });            
wirey00
  • 33,517
  • 7
  • 54
  • 65
Dynelight
  • 2,072
  • 4
  • 25
  • 50

0 Answers0