如何在没有重装的情况下刷新页面?

时间:2013-12-09 19:57:39

标签: javascript php jquery ajax

我现在有一个包含许多条目的页面,我正在使用2这样的页面URL

http://localhost/DS/abc.php?id=1

1-280-12 / 09/2013-ER-0-删除 2-280-12 / 09/2013-edr-0-delete ..... 所以,当我删除它时,转到带有空白id和当前id的页面被删除。我希望它应该重新加载或保持在同一页面上重新加载到相同的id.Here id = serial no in column 1,2和280是部分号我的删除代码是

<?php
      include_once('db.php');

    if( isset($_GET['del']) )
       {
$id = $_GET['del'];
$sql= "DELETE FROM audi WHERE id='$id'";
$res= mysql_query($sql) or die("Failed".mysql_error());
echo "<meta http-equiv='refresh' content='0;url=abc.php?id='.$id.''>";

       }   ?>

2 个答案:

答案 0 :(得分:0)

    <?php
      include_once('db.php');

    if( isset($_GET['del']) )
       {
$id = $_GET['del'];
$sql= "DELETE FROM audi WHERE id='$id'";
$res= mysql_query($sql) or die("Failed".mysql_error());

echo "<meta http-equiv='refresh' content='0;url=abc.php?id=".$id."'>"; // <- CORRECTION

       }   ?>

答案 1 :(得分:0)

您可以使用AJAX来实现这一目标:

用这样的javascript创建一个html页面:

<html>

<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>

    <script>
        function deleteEntry(del) {
            $.ajax({
                type: 'GET',
                url: 'delete.php',
                data: { del: del},
                success: function(response) {
                    alert('Entry Deleted')
                }
            });
        }
    </script>

</head>

<body>

    <button onclick="deleteEntry(5)">Delete Entry</button>
    <!--5 is the del variable-->

</body>
</html>

然后创建一个名为“delete.php”的php文件,如下所示:

<?php
  include_once('db.php');

    if( isset($_GET['del']) )
    {
        $id = $_GET['del'];
        $sql= "DELETE FROM audi WHERE id='$id'";
        $res= mysql_query($sql) or die("Failed".mysql_error());
   }   
?>

让我知道这是否有效,欢呼!

物理“删除”按钮仅用于显示,您可以使用相同的原则在传递删除ID时不断重新加载php文件。

相关问题