Django接受ajax传过来的数组

$.ajax({
            cache: false,
            type: "POST",
            url: "/userdelete/",
            traditional:true,  //加上此项可以传数组
            dataType:'json',
            async: true,
            data:{ids:data},  //<QueryDict: {'ids': ['40', '39', '33', '31', '29', '28']}>
            success: function(data) {
                if (data.status == 'success') {
                    $table.bootstrapTable('remove', {field: 'id', values: ids});
                }

            },
            beforeSend: function(xhr, settings) {
                xhr.setRequestHeader("X-CSRFToken", csrftoken);
            }
        });




    if request.is_ajax():
        if request.method == 'POST':

            array = request.POST.getlist('ids')  #django接收数组


            for i in array:
               p = UserProfile.objects.get(id=i)
               p.delete()


        return HttpResponse('{"status":"success"}', content_type='application/json')

猜你喜欢

转载自blog.csdn.net/xiguatony/article/details/81702535