我有我的网页的链接/按钮应该引导用户到一个CSV文件。 CSV文件是动态生成使用PHP,基于一些POST变量:
I have a link/button on my page that should lead the user to a csv file. The csv file is generated dynamically using PHP, based on some POST variables:
<?php
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=e".date('ymdHis').".csv");
...
?>
我
如何可以重定向到脚本,同时通过POST变量,而无需使用一种形式?
How can I redirect to the script, at the same time passing POST variables, without using a form?
解答我发现,我真的不喜欢:
Answers I found that I didn't really like:
与所需的变量,创建一个隐藏的POST形式,使用JavaScript触发后 使用jQuery.post加载网页 - 我还没有看到,我可以使用jQuery或AJAX一般重定向的页面您可以使用GET方法 - 用户将看不到GET字符串(丑陋的URL),它不会显示在新窗口。但是,如果你真的需要POST(虽然我不能想象为什么),你应该隐藏字段创建表单 - 这就是做你的任务的唯一方法(是的,我以前说这句话的测试方法很多)
You may use GET method - user won't see GET string (ugly URL), it won't be displayed in the new window. But if you really need POST (though i cannot even imagine why), you should create form with hidden fields - this is the only way to do your task (yes, i've tested many ways before saying this).