2012-06-12 77 views
3

我通过AJAX从数据库中获取HTML,但是当我将该HTML输出到div中时,它只显示实际的HTML文本,而不是图片,而浏览器则会看到它。有人知道怎么做吗?我在textarea #html中输出HTML,并希望看到它在div #preview中呈现。这里的代码:jQuery/AJAX读取div标签中的html

$(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); 
       } 
      } 
     }) 
    }); 
}); 
+0

如果您使用Firefox,请尝试使用Web控制台和Page Inspector检查更改。 HTML是否真的被放置在'#preview'中? –

+0

嘿@RobertNiestroj - 是它在里面#preview,但作为实际的HTML(

user1431633

+0

嘿@RobertNiestroj - 我使用ColdFusion返回查询,这里是一个Firebug中的响应示例:​​ < img src =“http://address.s3.amazonaws.com/folder/07/01.jpg”width =“600”height = “87”alt =“我们的alt”border =“0”> user1431633

回答

0

我通常使用$("myul").append("<li>anitem<\li>").给一个镜头,看看它是否工作。

2

我看到你回答了你自己的问题。你也可以考虑jQuery .load()方法,它是为这种事情设计的。