JS Replace函数未按预期工作

时间:2012-06-01 12:35:09

标签: javascript jquery

我有一个后端CGI脚本,如果通过AJAX调用出现问题,它会在文本下方返回:

<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]

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

您正在使用html形成的jQuery对象并将其转换为字符串。结果为[object OBJECTTYPE],在本例中为[object Object]

相反,只需尝试var StrippedString = html.replace(...);

相关问题