繁体   English   中英

jQuery-在请求后传递数组

[英]jQuery - passing arrays in post request

我想在jquery $ .post()请求中传递数组。

HTML:

<input type="checkbox" id="add-check-1e30">
<input type="checkbox" id="add-check-1230">

从上面的示例HTML中,数组应如下所示= ['1e30','1230']

jQuery发送$ .post():

$("#addbox-add").click(function(){

var ukeys = new Array();
$("input[type=checkbox]:checked").each( function() {
a = $(this).attr("id");
b = a.split('-').pop();
ukeys.push(b);
});

$(".addbox").remove();

$.post("/information/portfolio/add/", {'ukeys': ukeys }, function(data) {
for(i=0; i<data.length; i++)
{
    ukey = data[i].ukey;
    image = data[i].image;
    service = data[i].service;
    if(data[i].smallimage != "")
    {
        image = data[i].smallimage;
    }
    if (image == null)
    {
        $(".portfolio-preview").append('<li class="portfolio-item" id="portfolio-item-'+service+'-'+ukey+'"></li>');
    }
    else
    {
        $(".portfolio-preview").append('<li class="portfolio-item" id="portfolio-item-'+service+'-'+ukey+'"><img class="portfolio-image" src="'+image+'" width="150px" height="150px"></li>');
    }
}
});

});

jQuery中的数组变量没有问题,我不知道如何在发布请求中发送它。

我应该在服务器中获得这两个值1e30和1230 但是我在服务器中获取的值为null。

这是用于在Python / Django中获取值的服务器代码:

def portfolio_add(request):
    ukeys = request.POST.get('ukeys', '')   
    .....etc.....etc......

谢谢!

您必须使用:

request.POST.getlist('ukeys', '')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM