用ajax功能和php删除行

编程入门 行业动态 更新时间:2024-10-11 15:18:55
本文介绍了用ajax功能和php删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个带有mysql数据的表,我添加了一个垃圾箱按钮,当我用ajax函数单击垃圾箱按钮时,我想删除每一行, 这是我的html:

i have a table with mysql Data,i add a trash button and i want remove each row when trash button is clicked with ajax function, this is my html:

<table border="1"> <?php $sql ="SELECT * FROM music"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_object($result)){ echo '<tr><td>'.$row->file_name.'</td><td>'.$row->composer.'</td><td>'.$row->lyric.'</td><td>'.$row->music_thumb.'</td><td>'.' <a href="#" id="'.$row->msuic_id.'" class="trash" > جذف کردن </a> '.'</td></tr>'; } ?> </table>

和我的ajax函数在这里:

and my ajax function here:

$(function(){ $('.trash').click(function(){ var del_id= $(this).attr('id'); var $ele = $(this).parent().parent(); $.ajax({ type:'POST', url:'delete.php', data:del_id, success: function(data){ if(data=="YES"){ $ele.fadeOut().remove(); }else{ alert("can't delete the row") } } }) }) });

,还有我的"delete.php"页面:

and also my "delete.php" page here:

<?php include('../db_inc.php'); $music_number = "POST['del_id']"; echo '$music_number'; $qry = "DELETE FROM music WHERE msuic_id ='$music_number'"; $result=mysql_query($qry); ?>

我认为我的问题是ajax函数; 谢谢

i think my problem is ajax function; thanks

推荐答案

尝试一下

$.ajax({ type:'POST', url:'delete.php', data:{del_id:del_id}, success: function(data){ if(data=="YES"){ $ele.fadeOut().remove(); }else{ alert("can't delete the row") } } }) })

并更改

$music_number = "POST['del_id']";

$music_number = $_POST['del_id'];

更多推荐

用ajax功能和php删除行

本文发布于:2023-10-10 17:44:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479297.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:功能   ajax   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!