I'm trying to format the data to send it to the server via ajax but I can't serialize exactly the inputs to get the correct array at the end, I cannot understand what I'm doing wrong.
<input name="option[16]" value="Value1">
<input name="option[17]" value="Value2">
<input name="option[18]" value="Value3">
var final_options = new Array();
$('input[name="option[]"]').each(function() {
final_options[$(this).attr('name')] = $(this).attr('value');
});
$.ajax({
type: "POST",
url:"./urlPost",
data: {final_options: final_options},
dataType: 'json',
success: function(data){
console.log('Ok');
}
});
On server side I need to translate it as;
array(
array(
'16' => 'Value1'
),
array(
'17' => 'Value2'
),
array(
'18' => 'Value3'
),
)
$("#formid").serialize()?