Django接受ajax传过来的数组

        $.ajax({
            cache: false,
            type: "POST",
            url: "/userdelete/",
            traditional:true,  //加上此项可以传数组
            dataType:'json',
            async: true,
            data:{ids:ids},
            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')

 

posted on 2017-04-13 17:34  星河赵  阅读(7645)  评论(0编辑  收藏  举报

导航