首页 > 代码库 > ajax 删除/修改单条数据

ajax 删除/修改单条数据

ajax代码

<script>
$(".onedel").click(function(){ if (!confirm("确认要删除?")) { window.event.returnValue = false; }else { var id = $(this).attr("data-id"); $.ajax({ url: "{:U(‘Phone/ajaxOnedel‘)}", type: "post", dataType: "json", data: {id: id,table:‘email_p‘}, success: function (data) { if (data.id == 1) { alert("删除成功"); window.location.href=("{:U(‘Phone/remail‘)}"); } } }) } });
</script>

控制器函数代码

public function ajaxOnedel(){
        $table = I("post.table");
        $map[‘readers‘] = $_SESSION[‘login‘];
        $map[‘emailid‘] = I(‘post.id‘);
        $data[‘statuss‘] = -1;

        $res =  M("{$table}")->where($map)->save($data);
        if( $res ){
            $this->ajaxReturn(array(‘id‘ => 1 ));
        }
}

 

ajax 删除/修改单条数据