我有以下代码删除mysql记录,我想转换它所以它将是一个ajax / jquery代码,所以我可以保持在从表中删除记录后的同一页面.
现在,它工作正常,但它不在同一页面上,我需要刷新页面才能看到结果.这只是完整代码的一部分.
一页上的所有代码.
//get the mysql results
//this is a repeated region
<?php echo $row['id']; ?><?php echo $row['title']; ?><?php echo $row['description']; ?>Delete
if ((isset($_GET['deleteid'])) && ($_GET['deleteid'] != "") && (isset($_POST['delete']))) {
$deleteSQL = sprintf("DELETE FROM my_table WHERE id=%s",
GetSQLValueString($_GET['deleteid'], "int"));
解决方法:
<?php echo $row['id']; ?><?php echo $row['title']; ?><?php echo $row['description']; ?>Delete
现在在本节中写下这个
$(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";
休息我希望你知道.希望这可以帮助
标签:php,jquery,mysql,ajax,sql-delete
来源: https://codeday.me/bug/0930/1836076.html