【问题标题】:Refreshing old page whilst closing current page and add a action in url在关闭当前页面的同时刷新旧页面并在 url 中添加操作
【发布时间】:2017-03-26 14:45:02
【问题描述】:

我正在尝试在提交表单后关闭窗口并刷新主页,然后在 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加载。

提前致谢

【问题讨论】:

  • 你实现action=enabled了吗?
  • 请发布完整代码
  • 我的回答在您的请求末尾添加了action=enabled。您的代码未处理 action=enabled
  • 好的,非常感谢。我将如何让我的代码处理该请求?

标签: javascript php url


【解决方案1】:

为此你可以使用这个

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>"
}

【讨论】:

  • 我将使用我在您的答案中使用的代码更新我的 OP,不需要刷新,因为它会加载一个新的 url,其中包含传递给 url 的信息,但它仍然不会传输数据
猜你喜欢
  • 2012-01-26
  • 2022-11-21
  • 2018-09-15
  • 1970-01-01
  • 2021-02-05
  • 2017-09-04
  • 2020-04-03
  • 1970-01-01
  • 2021-12-31
相关资源
最近更新 更多