使用php删除记录而不刷新页面

使用php删除记录而不刷新页面,php,jquery,ajax,partial-page-refresh,Php,Jquery,Ajax,Partial Page Refresh,我有如下HTML和PHP代码: HTML <a href="deleteData.php?id=<?php echo $value['id']?>"><button name="delte" class="btn">Delete</button></a> deleteData.php <?php include ('include/connectdb.php'); $getid = $_GET['id']; $sql = (

我有如下HTML和PHP代码:

HTML

<a href="deleteData.php?id=<?php echo $value['id']?>"><button name="delte" class="btn">Delete</button></a>

deleteData.php

<?php
include ('include/connectdb.php');
$getid = $_GET['id'];
$sql = ("UPDATE tblworkfaire SET status=0 where id = ".$getid);
$res = mysql_query($sql) or die (mysql_error());

?>


这非常有效,只是删除记录后,记录仍会显示在页面上,直到刷新为止。如何修复此问题。任何人有任何想法请帮助我。谢谢,

使用重定向('my_original_page.php')它将重定向到您的主页面,但应该在执行删除查询后放置它。

使用重定向('my_original_page.php')它将重定向到您的主页面,但应该在执行删除查询后放置它。

您应该使用
Ajax
。尝试使用
jQuery


然后
onSuccess
方法也使用jQuery删除行。

您应该使用
Ajax
。尝试使用
jQuery


然后
onSuccess
方法也使用jQuery删除行。

您必须使用AJAX

使用本教程


它将帮助您解决问题。

为此,您必须使用AJAX

使用本教程

它会帮你的。

试试这样的方法---

试试这样的---

Creaet Delete.php文件

 include_once'DBConnect.php';
 if(isset($_REQUEST['userid']) && $_REQUEST['userid'])
 {
 $delObj= new DBConnect();
 $delObj->DeleteData($_REQUEST['userid']);
 }
创建DBConnect.php文件

<?php

class DBConnect
{
function DBConnect()
{
    $link= mysql_connect("localhost","root","")or die("Local Host Error".mysql_error());
    mysql_select_db("mydb");

}

 function viewData()
{

    $query="select * from userinfo";
    $resultset=mysql_query($query) ;

    return $resultset;


}

function DeleteData($userID)
{

    $query="DELETE from userinfo where id=".$userID;

    $resultset=mysql_query($query) ;

}


}

?>

创建index.php文件

<script>
function deletedata(id)
{
    var xmlhttp;    
    if (id=="")
      {
          document.getElementById("Display").innerHTML="";
          return;
      }
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
      }
    else
    {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
          {
            window.location.reload()

          }
    }
        xmlhttp.open("GET","delete.php?userid="+id,true);
        xmlhttp.send();

}
</script>    




<?php include 'DBConnect.php';
$ViewObj= new DBConnect();
$ResultSet=$ViewObj->viewData();?> // I have created one function which will get all the data from the database if you don't want to do this just call deletedata() function onClick event and pass Record ID as agrument which you want to delete on DELETE button.
<br /><br /><br />
<span id ="Display">
<table align="center" border="1">
<tr>
      <th>Name</th>
      <th>operation</th>
</tr>
<?php
while($row= mysql_fetch_array($ResultSet))
{?>


<tr>
    <td><input type="checkbox"></td>
    <td><?php echo $row[1];?></td>

    <td align="center"><a href="#" onclick="deletedata('<?php echo $row[0];?>')" style="color:#FF0000"><b>Delete</b></a>

    </td>
</tr>

<?php 


}
?>
</table>

函数deletedata(id)
{
var-xmlhttp;
如果(id==“”)
{
document.getElementById(“显示”).innerHTML=“”;
返回;
}
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
window.location.reload()
}
}
open(“GET”、“delete.php?userid=“+id,true”);
xmlhttp.send();
}
//我创建了一个函数,如果您不想这样做,它将从数据库中获取所有数据,只需调用deletedata()函数onClick event并在delete按钮上将记录ID作为要删除的记录传递。



名称 活动
我想这会帮助你:)

如果发现任何问题,请告诉我。

Creaet Delete.php文件

 include_once'DBConnect.php';
 if(isset($_REQUEST['userid']) && $_REQUEST['userid'])
 {
 $delObj= new DBConnect();
 $delObj->DeleteData($_REQUEST['userid']);
 }
创建DBConnect.php文件

<?php

class DBConnect
{
function DBConnect()
{
    $link= mysql_connect("localhost","root","")or die("Local Host Error".mysql_error());
    mysql_select_db("mydb");

}

 function viewData()
{

    $query="select * from userinfo";
    $resultset=mysql_query($query) ;

    return $resultset;


}

function DeleteData($userID)
{

    $query="DELETE from userinfo where id=".$userID;

    $resultset=mysql_query($query) ;

}


}

?>

创建index.php文件

<script>
function deletedata(id)
{
    var xmlhttp;    
    if (id=="")
      {
          document.getElementById("Display").innerHTML="";
          return;
      }
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
      }
    else
    {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
          {
            window.location.reload()

          }
    }
        xmlhttp.open("GET","delete.php?userid="+id,true);
        xmlhttp.send();

}
</script>    




<?php include 'DBConnect.php';
$ViewObj= new DBConnect();
$ResultSet=$ViewObj->viewData();?> // I have created one function which will get all the data from the database if you don't want to do this just call deletedata() function onClick event and pass Record ID as agrument which you want to delete on DELETE button.
<br /><br /><br />
<span id ="Display">
<table align="center" border="1">
<tr>
      <th>Name</th>
      <th>operation</th>
</tr>
<?php
while($row= mysql_fetch_array($ResultSet))
{?>


<tr>
    <td><input type="checkbox"></td>
    <td><?php echo $row[1];?></td>

    <td align="center"><a href="#" onclick="deletedata('<?php echo $row[0];?>')" style="color:#FF0000"><b>Delete</b></a>

    </td>
</tr>

<?php 


}
?>
</table>

函数deletedata(id)
{
var-xmlhttp;
如果(id==“”)
{
document.getElementById(“显示”).innerHTML=“”;
返回;
}
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
window.location.reload()
}
}
open(“GET”、“delete.php?userid=“+id,true”);
xmlhttp.send();
}
//我创建了一个函数,如果您不想这样做,它将从数据库中获取所有数据,只需调用deletedata()函数onClick event并在delete按钮上将记录ID作为要删除的记录传递。



名称 活动
我想这会帮助你:)


如果您发现任何问题,请告诉我。

您可以使用php函数标题('location:yourPage.php')或借助Ajax进行操作。

您可以使用php函数标题('location:yourPage.php')或在Ajax的帮助下执行

以下是删除记录而不刷新页面的完整源代码

按照以下步骤操作:

 delete.php
 index.php
步骤1:

 delete.php
 index.php
DBConnect.php

第二步:

 delete.php
 index.php
第三步:

 delete.php
 index.php

函数deletedata(id)
{
var-xmlhttp;
如果(id==“”)
{
document.getElementById(“显示”).innerHTML=“”;
返回;
}
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
window.location.reload()
}
}
open(“GET”、“delete.php?userid=“+id,true”);
xmlhttp.send();
}
身份证件
名称
活动
行动
如果你觉得有什么问题,请告诉我。希望能对你有所帮助。 多谢各位

以下是删除记录而不刷新页面的完整源代码

按照以下步骤操作:

 delete.php
 index.php
步骤1:

 delete.php
 index.php
DBConnect.php

第二步:

 delete.php
 index.php
第三步:

 delete.php
 index.php

函数deletedata(id)
{
var-xmlhttp;
如果(id==“”)
{
document.getElementById(“显示”).innerHTML=“”;
返回;
}
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
window.location.reload()
}
}
open(“GET”、“delete.php?userid=“+id,true”);