django ajax checkbox,python - Jquery and Django multiple checkbox - Stack Overflow

这篇博客探讨了一位初学者在使用jQuery处理多个选中复选框的值,并通过Ajax发送到Django视图进行处理时遇到的问题。在客户端,作者创建了一个函数来获取选中复选框的值并拼接成字符串。然后,通过Ajax发送GET请求到服务器。然而,服务器端只处理了部分发送过来的索引。问题可能出在服务器端对GET参数的处理上。
摘要由CSDN通过智能技术生成

I am a beginner in jquery so please bear with me.

I have a jquery function that allows me to select multiple checkboxes and create a string as follows:

function getSelectedVals(){

var tmp =[];

$("input[name='checks']").each(function() {

if ($(this).attr('checked'))

{

checked = ($(this).val());

tmp.push(checked);

}

});

var filters = tmp.join(',');

alert(filters)

return filters;

}

I then call a django view function and pass the string as follows:

selected = getSelectedVals();

var myurl = "/bills/delete/?id=" + selected;

$.ajax({

type: "GET",

url: myurl,

data: selected,

cache: false

});

On the server I have a delete view function that iterates over the checkbox values and manipulates a list.

def delete(request):

global myarray

idx = request.GET[u'id']

listidx = idx.split(',')

for l in listidx:

value = myarray[int(l)]

myarray.remove(value)

return HttpResponse("/bills/jqtut/")

The problem is that on the server all the indexes I am sending as the GET string are not being handled, only half are.

Please help me! Thanks

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值