继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

JQuery ajax 保存数据,删除数据

ios开发零基础入门
关注TA
已关注
手记 265
粉丝 20
获赞 110

 <script type="text/javascript">       //ajax 提交表单数据        $("#add_budget_submit").click(function () {            $.ajaxSetup({                data: {csrfmiddlewaretoken: '{{ csrf_token }}'},            });            $.ajax({                url: '{{ request.path }}',                type: 'POST',                data: $('#budgetForm').serialize(),                datatype: 'JSON',                success: function (obj) {                    var myjson = $.parseJSON(obj);                                      if (myjson["status"] == true) {                        layer.msg("添加成功!", {time: 1000});                        window.location.href = "budget_mgr";                    }                    else{                        layer.msg("添加失败!", {time: 1000});                    }                },                error: function () {                }            })        });        $(".del_budget").click(function () {             var p =$.trim($(this).parent().prev().prev().prev().prev().prev().text());           var tag_id = $(this).attr("tid");                 layer.open({            type:1,            skin:"layui-layer-rim",            area:["400px","200px"],            title:"删除预算",            content:'<div class="text-center" ><p>是否删除 ['+p+'] 年度预算?</p></div>',            btn:['确定','取消'],            yes:function () {                $.ajaxSetup({                    data:{csrfmiddlewaretoken:'{{ csrf_token }}'},                            });                $.ajax({                    url:'{% url "del_budget" %}',                    type:"POST",                    data:{"tag_id":tag_id},                    success:function (e) {                        if (e=="1"){                            parent.location.reload();                            layer.msg("删除成功!",{time:1000});                        }else {                            layer.msg("删除失败",{time:1000});                        }                    }                })            }            }) ;        })    </script>

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP