I have some textboxes generated dynamically through Ajax. I’m using Jackson 1.9.8 to parse json. I can retrieve the values of those dynamic textboxes using jQuery as follows.
var itemsArray=[];
$('input[name="txtChargeSize[]"]').each(function(){
itemsArray[i][2]=$(this).val();
});
This can retrieve each element of the textbox array txtChargeSize[] one by one.
itemsArray is an array which already holds
The value of weightId on the itemsArray[i][0] position,
The value of weight on the itemsArray[i][1] position,
The value of charge on the itemsArray[i][2] position which is the value of the textbox being assigned in the above code.
I need to pass this array to Spring controller class to insert these values into the Oracle database. I’m trying the following.
var i=0;
$('input[name="txtChargeSize[]"]').each(function(){
itemsArray[i][2]=$(this).val();
objectArray[i]=[["weightId",itemsArray[i][0]], ["weight",itemsArray[i][1]], ["charge",itemsArray[i][2]]];
i++;
});
It doesn’t work as I expect. I need to pass something like the following.
[["weightId", 1], ["weight", 12.4], ["charge", 15.5]]
so that it can be parsed to java.util.List<Object[]>. I don’t have precise knowledge of Javascript to accomplish this. How can I pass in this way the values held by itemsArray to Spring controller using json?
try javascript constructor method like this.
and the constructor function is
and finally if you want json string then use this