I have an issue which I want to get all the data from list
, so I want to loop every single data from selected items and insert it to database,
currently it returns the data like this when I print it ['[object Object]', '[object Object]']
,
how can I insert these data one by one? or just print it one by one?
I have this list which is selected_items I loop the data and then pass it to ajax
selected_items = [];
for (var i = 0; i < checkBoxes.length; i++) {
var selected_obj ={
stock_id: checkBoxes[i].id,
quantity: row.cells[3].innerHTML
}
selected_items.push(selected_obj);
}
when console the selected_items it’s just like this
so now I want to pass these list to django using ajax
console.log(selected_items);
$.ajax({
type: "POST",
url: "{% url 'sales-item' %}",
data:{
multiple_list: selected_items.join(','), item_size: selected_items.length
}
}).done(function(data){...
views.py
out_items = request.POST.getlist('multiple_list[]')
print(out_items)
and it prints like this
['[object Object]', '[object Object]']