I am using the JS window.location
as:
window.location.href = "my_url.php?param=1"
my_url.php
having again redirect using header()
function.
If param=1
I am having code for download CSV , otherwise redirect to other URL.
UPDATE:
Redirect using JS:
// Download CSV
$( '#download_csv' ).on( 'click', function() {
window.location.href ="my_url.php?param=1"; // param is dynamic will be sent or not
});
my_url.php
if($param == 1)
{
//CODE for download CSV, It works fine as intended
}
else
{
header("Location:other_page.php");//no actual redirect happens, instead I got ajax output of other_page.php
exit;
}
Problem: whatever the output of other_page.php it will get printed but my Addressbar is having the URL of my_url.php
If you want to check param
in my_url.php and according to it if you have to redirect then check param using $_GET then apply redirection
my_url.php
$param = (isset($GET['param']))?GET['param']:"";
if($param == 1)
{
//CODE for download CSV,
}
else
{
header("Location:other_page.php");//redirect to other page
exit;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.