2012-06-01 31 views
0

我有一个后端CGI脚本,通过Ajax调用返回我下面的文字中出现问题时:JS更换功能不按预期工作

<p>A problem occurred in a Python script. 
<p> /bin/cgi-bin/LOGS/tmpslM4pu.txt contains the description of this error. 

我试图像下面显示出来:

$.ajax({ 
      type: "POST", 
      url: "runcgi.py", 
      data: 
      { 
       'my_data' : 'test' 
      }, 
      success: function(html) 
      { 
       if(..test for success..) 
       { 
       } 
       else 
       { 
          var StrippedString = $(html).toString().replace(/(<([^>]+)>)/ig,"");                       var StrippedString = $(html).toString().replace(/(<([^>]+)>)/ig,""); 
          $("p").html(StrippedString); 

       } 
}); 

而下面是我的HTML代码:

<body> 
     <p></p> 
</body> 

但我看到下面的输出在我的浏览器:

[object Object] 

我该如何解决这个问题?

+0

使用console.log(html)在Firefox中使用Google Chrome或Firebug,然后在控制台视图中检查元素。 – Christian

回答

3

您正在使用由html组成的jQuery对象并将其转换为字符串。结果是[object OBJECTTYPE],在这种情况下是[object Object]

取而代之,试试var StrippedString = html.replace(...);

+0

我曾尝试过,但它声明,html.replace不是一个函数,这就是为什么我添加toString()。使用FireBug我看到$(html)具有值'Document' – Prakash