2016-11-12 18 views
4

我想在表單提交後關閉一個窗口,並刷新主頁面,然後在URL內傳遞信息以執行操作彈出窗口。刷新舊頁面,同時關閉當前頁面,並在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加載。

提前

+1

你實現'行動= enabled'? –

+0

是的,我有,我確定我錯過了一些非常基本的東西 – thenashone

+1

請發佈整個代碼 –

回答

3

非常感謝這一點,你可以用這個

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

我會更新我的OP與我用你的答案的代碼,刷新是不需要的,因爲它會加載一個新的URL與信息傳遞到該網址,但它仍然不會傳輸數據 – thenashone