无法使用jQuery和php $ _GET导出html表格

我下载的表格只打印标题,并不显示任何内容。 IAM从这里教程: http : //webslesson.blogspot.in/2016/02/export-mysql-data-to-excel-in-php-php-tutorial.html

下面的插件我已经尝试过无法呈现我的巨大数据1.clarketm(合并行)2.(尝试但无法渲染巨大的数据) https://github.com/kayalshri/tableExport.jquery.plugin

我的HTML DOM IS( index.php

<div id="allTables"> <table border="2" width="100%"> <tr> <th width="30%">Name</th> <th width="20%">Activity on Code Project (%)</th> <th width="10%">Activity on C# Corner (%)</th> <th width="10%">Activity on Asp Forum (%)</th> </tr> <tr> <td>Sibeesh</td> <td>100</td> <td>98</td> <td>80</td> </tr> <tr> <td>Ajay</td> <td>90</td> <td>0</td> <td>50</td> </tr> </table> </div> <p id="exportexcel">EXport to Excel</p> <script> $(document).ready(function () { $('#exportexcel').click(function(){ var excel_data = $('#allTables').html(); console.log(excel_data); var page = "excel.php?data="+excel_data; console.log(page); window.location = page; // here iam sending data to excel.php through get method }); </script> 

我的excel.php文件是

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

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

在C#angular上的活动(%) – “#”在这一行是造成这个问题。 编码这将解决上面的代码中的问题。

但build议使用POST更好。

如果你通过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> 

你的excel.php文件应该是

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

如果你想使用$ _GET,那么你应该参考我怎样才能在PHP PHP解码? 在javascript中编码和解码uri到php