[英]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.