I have a list that I created with jQuery as follows:
pros=[];
cons=[];
$.each($(".pro-item"), function(){
pros.push($(this).html())
})
$.each($(".con-item"), function(){
cons.push($(this).html())
})
Now I want to pass it to server for processing, so I use Ajax:
$.ajax({
data: {
pros: pros,
cons: cons,
},
type: 'POST',
dataType: "json",
traditional: true,
url: '/pro_con_list',
success: function(data){
console.log("Ajax call successful")
}
})
But when server(flask/python) receives it and I print the resulting data as such:
pros = request.form.get("pros")
print(pros)
print(request.form.get("cons"))
It only prints the first item of the JS list that was sent. I console.log both pros and cons lists and it shows full lists:
(3) ["foo", "foo bar", "foo bar buz"]
(3) ["buz", "buz bar", "buz bar foo"]
And this is what python prints it received:
foo
buz
I assume I am not sending the the list properly, but the seemed to be the only way working and not printing None.