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
Javascript jquery发布成功函数不返回html页面_Javascript_Jquery - Fatal编程技术网

Javascript jquery发布成功函数不返回html页面

Javascript jquery发布成功函数不返回html页面,javascript,jquery,Javascript,Jquery,我在一个perl程序中有一个javascript/jquery函数,它返回一个完整的HTML页面,我想使用jquery的.post将CGI值提交给程序,并根据提交的数据重新加载页面进行进一步处理 考虑以下mcve: #!/usr/bin/perl use CGI; my $cgivars = CGI->new; my $data = $cgivars->param('DATA'); my $something = "This is some data."; my $display

我在一个perl程序中有一个javascript/jquery函数,它返回一个完整的HTML页面,我想使用jquery的.post将CGI值提交给程序,并根据提交的数据重新加载页面进行进一步处理

考虑以下mcve:

#!/usr/bin/perl
use CGI;
my $cgivars = CGI->new;
my $data = $cgivars->param('DATA');

my $something = "This is some data.";

my $display = qq|Content-type: text/html\n\n<http><head></head><body>The data submitted was $data</body></http>|;
my $postdata = qq|Content-type: text/html\n\n
        <http><head><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script></head>
        <body>
        <script type="text/javascript">
        function postData() {
        \$.post("jqpost.cgi",{DATA:"$something"});
        }
        </script>
        Click the button to submit some data<br>
        <button value="submit" onclick="postData()">Submit</button>
        </body></html>|;

if ($data) {
    print $display;
} else {
    print $postdata;
}
end;
firebug的控制台显示一个200(OK),All/HTML选项卡显示我希望返回的页面,传递的数据按预期使用。我发现上面的代码没有包含管理返回结果的函数。 所以我尝试使用一个函数来加载我知道返回的页面,使用

$.post("jqpost.cgi",{DATA:"$something"},function(data) { document.write(data);});
页面开始在浏览器中加载,但页面从未完成加载。Apache的日志没有显示任何附加数据


成功功能如何正确/完整显示从服务器返回的整个页面?

您需要关闭
文档。打开
<代码>文档。写入
打开文档

document.write("Hello there!!!");
document.close();

不再旋转。

你从你的程序中得到了什么,一个HTML、JSON等字符串?它真的是“整页”还是仅仅是
,或者是要附加/插入到特定位置的其他元素?在发出Ajax请求之前,您的“”HTML是什么?你得到了什么回应?您希望或需要什么样的精确结果/输出?我已经对帖子进行了重组,以使用MCVE来演示这个问题。
document.write("Hello there!!!");
document.close();