I'm getting HTML from a database via AJAX but when I output that HTML into a div, it only shows the actual HTML text, not the pictures and such as a browser sees it. Anyone know how to do this? I'm outputting the HTML in textarea #html and want to see it rendered in div #preview. Here's the code:
$(document).ready(function(){
$('#creative').change(function() {
$.ajax({
url: '/app/components/MailingsReport.cfc',
//POST method is used
type: "POST",
//pass the data
data: {
method: "getCreativeHTML",
creativeID: $('#creative').val(),
datasource: "shopping_cart"
},
dataType: "html",
//contentType: "application/text; charset=utf-8",
success: function(response){
var obj = $.trim(response);
//alert("response");
if (obj == '"0 records"') {
$('#preview').html("No creative found.");
}
else {
$('#html').val( obj );
$('#preview').html( obj );
}
}
})
});
});
I see you answered your own question. You could also consider the jQuery .load() method, which is designed for this sort of thing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With