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)
页面的连接就不放了。
我不是来改变世界的