I want to get the value of associative hidden fields array in PHP by posting it through jquery ajax, currently I am trying in this way
Here, HTML Code is:
<input type="hidden" class="override_arr" name="override_arr[][id]" value="1">';
<input type="hidden" class="override_arr" name="override_arr[][override_price_second]" value="5">';
<input type="hidden" class="override_arr" name="override_arr[][override_price_third]" value="10">
Jquery Code
var new_override_arr = [];
$('input.override_arr').each(function(i, elem) {
new_override_arr.push({
'id': $(elem).attr('id'),
'override_price_second': $(elem).val(),
'override_price_third': $(elem).val(),
});
});
var formData = new FormData();
formData.append('new_override_arr', new_override_arr);
**Call Ajax**
$.ajax({
url:'sa-store-view.php',
type:'POST',
data:formData,
success:function(result){
}
});
Try to get value in php file(sa-store-view.php)
<?php
echo "<pre>";print_r($_POST['new_override_arr']);
?>
but displaying like this
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
please help me.
2
Answers
.serialize()
should workYou can let PHP know that FormData element is an array