Javascript JS Replace函数未按预期工作
我有一个后端CGI脚本,通过AJAX调用在出现问题时返回以下文本:Javascript JS Replace函数未按预期工作,javascript,jquery,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. 如何解决这个问题?您正在获取由html形成的jQuery对象,并将其转换为字符串。结果是[objectobjecttype],在本例中是[objectobject] 相反
<p>A problem occurred in a Python script.
<p> /bin/cgi-bin/LOGS/tmpslM4pu.txt contains the description of this error.
如何解决这个问题?您正在获取由
html
形成的jQuery对象,并将其转换为字符串。结果是[objectobjecttype]
,在本例中是[objectobject]
相反,只需尝试
var StrippedString=html.replace(…)
您正在获取由html
形成的jQuery对象,并将其转换为字符串。结果是[objectobjecttype]
,在本例中是[objectobject]
相反,只需尝试
var StrippedString=html.replace(…)
在Firefox中使用console.log(html)和Google Chrome或Firebug,并在console视图中检查元素。在Firefox中使用console.log(html)和Google Chrome或Firebug,并在console视图中检查元素。我已经尝试过了,但它声明html.replace不是一个函数,这就是我添加toString()的原因。使用FireBug,我看到$(html)的值为“Document”,我已经尝试过了,但它表明html.replace不是一个函数,这就是我添加toString()的原因。使用FireBug,我看到$(html)的值为“Document”
$.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);
}
});
<body>
<p></p>
</body>
[object Object]