我试图关闭一个窗口后,一个表单已提交,并刷新主页面,然后传递一个动作弹出的url内的信息。
我有代码工作良好,但似乎不能传递信息。
下面是工作代码
echo "<script>window.close();window.opener.location.reload(true);</script>";
我已经尝试了以下,我知道这是错误的,但不确定在哪里寻求答案,因为不太确定要搜索什么
<?php
// include database connection
$id=isset($_GET['id']) ? $_GET['id'] : die('ERROR: Record ID not found.');
// include database connection
include '../../../assets/connect.php';
try {
// get record ID
// isset() is a PHP function used to verify if a value is there or not
// delete query
$query = "DELETE FROM investment_return Where id = '$id'";
$stmt = $con->prepare($query);
$stmt->bindParam(1, $id);
if($stmt->execute()){
// redirect to read records page and
// tell the user record was deleted
echo "<script>window.close();window.location.href = window.location.href + '?action=entered';</script>";
}else{
die('Unable to delete record.');
}
}
// show error
catch(PDOException $exception){
die('ERROR: ' . $exception->getMessage());
}
?>
正如你可以告诉我,我正试图添加?action=entered
到url的末尾。
上面的代码关闭了窗口,但没有添加到末尾所需的信息,现在不需要刷新,因为它将是一个新的url加载。
Many Thanks in advance
可以使用
window.location.href = window.location.href + "?action=entered";
改变当前window
的位置。
例如,如果您的页面是https://www.google.com
,它将重定向到https://www.google.com?action=entered
处理您的请求添加
if (isset($_GET['action'] && $_GET['action'] == 'enabled') {
//here add your code for example
echo "<script>alert('deleted');</script>"
}