我正在制作一个表单(form.php)供用户插入数据,用户插入数据后,表单操作将跳转到formGenerateXLS.php (使用POST方法)以生成用户数据到XSL文件。在formGenerateXLS.php的底部,我放了一段javascript代码来跳转到仪表板(home.php),但它失败了。Excel文件已成功生成,但javascript代码无法工作。如何使用它呢?
if(isset($_POST['issue_time'])){
$product_desc = $_POST['product'];
$filename_excel = date("Ymd_")."$product_desc";
header("Content-type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=$filename_excel.xls");
echo "<table border='1'>";
echo "<tr>";
echo "<th colspan='3' bgcolor='#1bf3b3'>New Ticket Request</th>";
echo "</tr>";
echo "<tr>";
echo "<td>Name</td>";
echo "<td></td>";
echo "<td>User</td>";
echo "</tr>";
echo "</table>"
}
echo "<script>window.location='home.php'</script>";发布于 2019-02-04 15:08:00
因为echo不执行该命令,而只是将其写入文件。为了重新定位php文件,可以使用header ()函数,例如header ('location: home.php');。
https://stackoverflow.com/questions/54509898
复制相似问题