手记

JQuery ajax 保存数据,删除数据

 <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>

0人推荐
随时随地看视频
慕课网APP