dongxian4531 2014-04-29 12:02
浏览 16
已采纳

不要通过ajax实时通话删除

When i press the delete button, it won't delete the content. I think there is something wrong on the ajax delete call

ajax-file.php

    $('.delete_update').live("click",function() {

        var ID = $(this).attr("id");
        var dataString = 'msg_id='+ ID;

        if(confirm("Sure you want to delete this update? There is NO undo!")) {

        $.ajax({
            type: "POST",
            url: "delete_data.php",
            data: dataString,
            cache: false,
            success: function(html){
            $("div#bar"+ID).slideUp('slow', function() {$(this).remove();});
        }
    });

    }

return false;
});

<div class="accordionButton" id="bar<?php echo $msg_id; ?>"><?php echo $msg_id; ?>:<?php echo $name; ?>
<a href="#" id="<?php echo $msg_id; ?>" class="delete_update">X</a>
</div>
<div class="accordionContent" style="display: block;"><?php echo $msg; ?></div>

delete_data.php

<?php
include("db.php");
if($_POST['msg_id'])
{
$id=$_POST['msg_id'];
$id = mysql_escape_String($id);
$sql = "delete from messages where msg_id='$id'";
mysql_query( $sql);
}
?>
  • 写回答

2条回答 默认 最新

  • duanguanya3052 2014-04-29 12:10
    关注

    If you are using latest jQuery then use on instead of live as it's not supported

    *Updated for dynamic content

    $(document).on("click", '.delete_update', function() {
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)