I am using Datatables. I have a table with multiple inputs and I want to post array of objects to controller via ajax.
var data = table.$('input, select').serialize();
The result:
row-1-location=123&row-1-lot=231545&row-2-location=2323&row-2-lot=5523&row-3-location=23232&row-3-lot=23235
I am assuming I need to split the string at every second '&', then split again. The question is, is this the only way to convert it to array of objects?
The result I want is array of objects:
[{location : 123, lot: 231545}, {location: 2323, lot: 5523}......]
HTML:
<tbody>
<tr role="row" class="odd">
<td><input type="text" id="row-5-location" name="row-5-location" value=""></td>
<td><input type="text" id="row-5-lot" name="row-5-lot" value=""></td>
</tr>
<tr role="row" class="even">
<td><input type="text" id="row-6-location" name="row-5-location" value=""></td>
<td><input type="text" id="row-6-lot" name="row-5-lot" value=""></td>
</tr>
</tbody>
Thanks!
datasimply becomes the BODY of your POST request.