Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JS Replace函数未按预期工作_Javascript_Jquery - Fatal编程技术网

Javascript JS Replace函数未按预期工作

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

我有一个后端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]


相反,只需尝试
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]