I am trying to pass an array of JS objects with 5 variables in the in the object. When trying to get the array of objects in the java servlet I keep getting a NULL. Passing a single variable or an object of variables works perfectly.
Java Servlet:
String [] s = req.getParameterValues("json[]");
I have also tried
String [] s = req.getParameterValues("json");
I added the []
because of this answer.
JavaScript code:
var list = [];
$(x).each(function(index, e) {
var y = $(e).find("input[id*='numOfShares']");
var id = y.attr('name');
var num = y.val();
var price = y.val();
var date = y.val();
var symbol = $("#holdSymb").val();
var hold = {
"holdingsID" : id,
"symbol" : symbol,
"purchasePrice" : price,
"numberOfShares" : num,
"purchaseDate" : date
};
list.push(hold);
});
$.ajax({
url:"URL",
type:"POST",
dataType:'json',
data: {json:list},//Also tried {'json':list},
success:function(data){
console.log("Done");
},
fail:function(data) {
console.log("Failed");
}
});