django 记录前后台交互ajax

前端:

<script>
        $(document).ready(function() {
            $('.edit-item').click(function () {
                var tr = $(this).parents('tr');
                var command_id = tr.children('td').eq(0).text();
                api_url = 'updateAlarm';
                $.ajax({
                    method: 'GET',
                    url: api_url,
                    data:{'id':command_id},
                    dataType: 'json',
                    success: function (data) {
                        if (data['status'] == "ok") {
                            alert("更新成功");
                            window.location.reload();
                        }else {
                            alert("更新失败")
                        }
            }
        })
            });
        });
    </script>

 

后端:

class AlarmsCommandUpdateView(View):
    # form_class = BasicSettingForm
    template_name = "alarms/alarm_list.html"
    permission_classes = [IsOrgAdmin | IsOrgAuditor]
    default_days_ago = 5
    model = ForbidCommand
    user = ''

    def get(self, request):
        try:
            data = request.GET
            idd = data.get('id')
            forb = ForbidCommand.objects.filter(id=idd).update(handle=2)
            result = {'status': 'ok'}
        except Error:
            result = {'status': 'false'}
        return JsonResponse(result, safe=False)

 

 

页面的连接就不放了。

 

posted @ 2020-09-11 17:45  忧伤还是快乐EL  阅读(234)  评论(0编辑  收藏  举报