【发布时间】:2021-06-15 14:49:48
【问题描述】:
如何在下面的代码中将变量list 发送到 Django?
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");
}
});
});
【问题讨论】:
-
你应该在这里粘贴你的django代码。其他人需要知道如何回答你的问题。
-
这将帮助你们,它对我有用stackoverflow.com/a/34951258/15527968
标签: javascript python django