Django接受ajax传过来的数组

Posted 一天一点到

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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‘)

 

以上是关于Django接受ajax传过来的数组的主要内容,如果未能解决你的问题,请参考以下文章

后台怎么接受并解析前端ajax传过来的json

jquery解析php通过ajax传过来的json二维数组对象

jquery通过AJAX接受PHP传过来的值。怎么接收?

form表单提交提交文件,并接受后端传过来的数据

django 接受 ajax 传来的数组对象

django 接受 ajax 传来的数组对象