Javascript 无法使用jquery和php$\u GET导出html表

Javascript 无法使用jquery和php$\u GET导出html表,javascript,php,jquery,excel,Javascript,Php,Jquery,Excel,我下载的表格只打印标题,不显示任何内容。 iam从这里开始学习教程: 我尝试过的以下插件无法呈现我的海量数据 1.clarketm(合并行) 2.(已尝试但无法呈现巨大的dat) 我的HTMLDOM是(index.php) 名称 代码项目活动(%) C#角活动(%) Asp论坛活动(%) 西比什 100 98 80 阿杰 90 0 50 导出到Excel $(文档).ready(函数(){ $('#exportexcel')。单击(函数(){ var excel_data=$('#allTab

我下载的表格只打印标题,不显示任何内容。 iam从这里开始学习教程:

我尝试过的以下插件无法呈现我的海量数据 1.clarketm(合并行) 2.(已尝试但无法呈现巨大的dat)

我的HTMLDOM是(index.php


名称
代码项目活动(%)
C#角活动(%)
Asp论坛活动(%)
西比什
100
98
80
阿杰
90
0
50
导出到Excel

$(文档).ready(函数(){ $('#exportexcel')。单击(函数(){ var excel_data=$('#allTables').html(); console.log(excel_数据); var page=“excel.php?data=“+excel\u数据; 控制台日志(第页); window.location=page;//这里我通过get方法将数据发送到excel.php });
我的excel.php文件是

<?php
  header('Content-Type: application/vnd.ms-excel');
  header('Content-disposition: attachment; filename='.rand().'.xls');
  echo $_GET["data"];
?>


--请帮助我我做错了什么,提前谢谢

如果您通过get传递html代码,那么您必须对其进行编码,否则您可以使用post方法。 下面的代码将对您有用

<script type="text/javascript">
 var htmlString= document.getElementById(allTables).innerHTML;
    $.ajax({
        type: "POST",
        url: "excel.php",
    dataType:'html',// ***add this option!***
        data: {html:htmlString},
        success: function (data) {
            // this is executed when ajax call finished well
             alert('file has been saved');
             location.reload();
        },
        error: function (xhr, status, error) {
            // executed if something went wrong during call
            if (xhr.status > 0) alert("Error: " + status); // status 0 - when load is interrupted
        }
    });
    }

</script>

var htmlString=document.getElementById(allTables).innerHTML;
$.ajax({
类型:“POST”,
url:“excel.php”,
数据类型:'html',/***添加此选项***
数据:{html:htmlString},
成功:功能(数据){
//这是在ajax调用顺利完成时执行的
警报(“文件已保存”);
location.reload();
},
错误:函数(xhr、状态、错误){
//在通话过程中出现问题时执行
如果(xhr.status>0)警报(“错误:+状态);//状态0-加载中断时
}
});
}
您的excel.php文件应为

<?php
  header('Content-Type: application/vnd.ms-excel');
  header('Content-disposition: attachment; filename='.rand().'.xls');
  echo $_POST["html"];
?>

如果您想使用$\u GET,那么您应该参考 将javascript中的uri编码和解码为php

此行中C#角(%)-“#”上的活动导致了问题。对其进行编码将解决上述代码中的问题


但最好按照建议使用POST。

我不确定GET字符串是否真的需要HTML,尤其是数据中的等号看起来像是有效的GET字符串分隔符。我认为您可能希望通过POST向您发送数据。也许您应该查看jQuery和$jQuery.POST()@Paul我看过为他们编写的教程,你可能需要对控制台中的excel#u数据进行url编码。log(excel#u数据);?@Abhijit,它类似于这个excel.php?数据=…整个数据,为什么你这么准确,我删除了C#Corner(%)上的活动,并且是个工作人员
<?php
  header('Content-Type: application/vnd.ms-excel');
  header('Content-disposition: attachment; filename='.rand().'.xls');
  echo $_POST["html"];
?>