我正在创建一个带有记录和删除按钮的表。每个删除按钮都有一个 id,我按下按钮删除记录。
下面的代码:
echo '<a class="delete" href="delete.php?id='.$id.'">Delete</a></td>';
输出html:
<a class="delete" href="delete.php?id=1">Delete</a>
<a class="delete" href="delete.php?id=2">Delete</a>
<a class="delete" href="delete.php?id=3">Delete</a>
<a class="delete" href="delete.php?id=4">Delete</a>
删除.php:
<?php
$id = $_GET['id'];
if(isset($_GET['messageid']))
{
$con=mysqli_connect("localhost","root","","mydb");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"DELETE from table WHERE id='$id'");
mysqli_close($con);
}
?>
上面的代码按预期工作,但我不想浏览到其他页面,所以我在想 JQuery Ajax。我知道如何将 jquery ajax 用于表单,但事实并非如此。如何让 JQuery Ajax 与我的代码一起工作?