[英]how window.location having again redirect in php file?
我使用 JS window.location
作为:
window.location.href = "my_url.php?param=1"
my_url.php
再次使用header()
函数重定向。
如果param=1
我有下载 CSV 的代码,否则重定向到其他 URL。
更新:
使用 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;
}
问题:无论 other_page.php 的输出如何,它都会被打印,但我的地址栏有 my_url.php 的 URL
如果你想在my_url.php 中检查param
并根据它是否必须重定向然后使用 $_GET 检查 param 然后应用重定向
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.