我有下面的代码删除mysql记录,我想对其进行转换,因此它将是ajax / jquery代码,因此从表中删除记录后,我可以留在同一页上。现在,它工作正常,但不在同一页面上,我需要刷新页面以查看结果。这只是完整代码的一部分。所有代码都在一页上。
//get the mysql results //this is a repeated region <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['title']; ?></td> <td><?php echo $row['description']; ?></td> <td><a href="manage.php?id=<?php echo $row['id']; ?>">Delete</a> </td> </tr> if ((isset($_GET['deleteid'])) && ($_GET['deleteid'] != "") && (isset($_POST['delete']))) { $deleteSQL = sprintf("DELETE FROM my_table WHERE id=%s", GetSQLValueString($_GET['deleteid'], "int"));
现在在本节中写下
$(document).ready(function(){ $(".delete_class").click(function(){ var del_id = $(this).attr('id'); $.ajax({ type:'POST', url:'delete_page.php', data:'delete_id='+del_id, success:function(data) { if(data) { // DO SOMETHING } else { // DO SOMETHING } } }); }); });
现在在“ delete_page.php”页面中执行此操作
$id = $_POST['delete_id']; $query = "delete from TABLE NAME where ID = $id";
休息,我希望你知道。希望这可以帮助