How can I send the variable list
to Django in the code below?
var list = [];
function add_item(item,next){
list.push(item.name);
item.parentNode.style.display = "none";
next.style.display = "block";
console.log(list); }
function remove_item(item,prev){
for (var i = 0; i <= list.length; i++) {
if (list[i]===item.name) {
list.splice(i,1);
} }
item.parentNode.style.display = "none";
prev.style.display = "block";
}
$(document).ready(function() {
$.ajax({
method: 'POST',
url: '/food_output',
data: {'list': list},
success: function (data) {
//this gets called when server returns an OK response
alert("it worked!");
},
error: function (data) {
alert("it didnt work");
}
});
});