简体   繁体   English

删除Javascript后刷新页面

[英]refreshing a page after deletion Javascript

I have a page filled with a list from a database, when clicking any element of this list, the details of this element will appear on another page to be edited. 我有一个页面,其中充满了数据库中的列表,单击此列表的任何元素时,此元素的详细信息将显示在要编辑的另一页上。 user also have the option of deletion here. 用户也可以在此处删除。 the problem is after deletion process completes the original page with the list doesnt refresh, so it still displays the deleted element in the list. 问题是删除过程完成了原始页面后,列表没有刷新,因此它仍然在列表中显示已删除的元素。 i tried different methods mentioned here in stackoverflow.com but none worked as i want. 我尝试了在stackoverflow.com此处提到的其他方法,但是没有一种方法可以按照我的要求进行。 for example this answer was mentioned here: 例如,这里提到了这个答案:

$sql = "delete from `lesson_plans` where `LP_ID` = '" . $_SESSION['LP_ID_S']."';";  
if ($conn->query($sql) === TRUE) 
    {    
        echo "<script>var hWndB = window.open('myplans.php'),
                hWndA = window.self;
                hWndB.onunload = function(){ hWndA.location.reload(); }
              </script>";
    }

the problem in this code that is opens a new page with new list successfully and keeps the old one open as well, so it doesnt refresh the old one, it only open a new link in a new tab. 此代码中的问题是成功地打开了一个具有新列表的新页面,并同时保持了旧页面的打开状态,因此它不会刷新旧页面,它只会在新选项卡中打开一个新链接。

You can refresh page in php add the below code header('Location: '.$_SERVER['REQUEST_URI']); 您可以在php中刷新页面,添加以下代码标头('Location:'。$ _ SERVER ['REQUEST_URI']); if header already exist error comes then add the ob_start() in top of the page 如果标题已经存在错误出现,则在页面顶部添加ob_start()

you need to refresh page in javascript then add below code 您需要刷新JavaScript页面,然后添加以下代码

location.reload(); location.reload();

You can try like this using windows.redirect you can reload the page. 您可以使用windows.redirect这样尝试,然后重新加载页面。

$sql = "delete from `lesson_plans` where `LP_ID` = '" . $_SESSION['LP_ID_S']."';";  
if ($conn->query($sql) === TRUE) 
{    
    echo "<script> window.location = "myplans.php"; </script>";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM