Redirect with POST to application/csv without form
I have a link/button on my page that should lead the user to a csv file. The csv file is generated dynamicall开发者_Go百科y using PHP, based on some POST variables:
<?php
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=e".date('ymdHis').".csv");
...
?>
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:
- Create a hidden POST form with the desired variables and trigger a post using javascript
- Use jQuery.post to load the page -- I don't yet see how I can use jQuery or AJAX in general to redirect the page
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).
精彩评论