Load HTML into DIV received via AJAX request converting special characters

2

I'm maintaining an application where there is now a need to load an HTML from the database into a div. As for the return of this HTML from the database, it's cool, I already get the values in a JSON and could (possibly) load it into the view, but it just does not load.

I'll show the code:

$.ajax({
    url: '<minha url>',
    dataType: 'html',
    type: 'post', 
    data: {<meus parametros>},
    success: function(data){
        $('#load-html-template').html(data[0].TemplateText);
    }

As for dataType , I already sent as HTML (does not return anything), JSON (returns the HTML as a string), XML (does not load anything), etc ...

Solved one part of the problem - entering another

Thanks for the help guys so far, but now I have direct access to the database and I noticed that the HTML code is in special character format, like this:

&lt;html&gt;
&lt;head&gt;

&lt;/head&gt;

&lt;body&gt;
    &lt;table border="0" cellspacing="0" cellpadding="0" width="100%"&gt;
        &lt;tr&gt;
            &lt;td width="2%"&gt;&amp;#160;&lt;/td&gt;
            &lt;td width="920px"&gt;
                 &lt;div style="line-height:120%;font-family:Arial;font-size:15pt;background-color:#e8eae8;"&gt;&lt;form action=""&gt;&lt;table border="0" cellspacing="1" cellpadding="0" width="99%"&gt;

......

Well, how to convert these tags to the HTML tags in question? I already did this, but still the problem goes ...

mystring.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;");

Could you give me strength !!! Thanks in advance!

    
asked by anonymous 24.09.2015 / 16:41

1 answer

1

I've tried the following:

var html = String(data[0].TemplateText).replace(/&amp;/g, '&')
        .replace(/&quot;/g, '"')
        .replace(/&#39;/g, "'")
        .replace(/&lt;/g, '<')
        .replace(/&gt;/g, '>');
    
24.09.2015 / 19:18