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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM