php - How to get hidden associative array field values inside jQuery post using ajax

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.
Answer
Solution:
.serialize()
should work
$.ajax({
url:'sa-store-view.php',
type:'POST',
data: $('input.override_arr').serialize(),
success:function(result){
}
});
Answer
Solution:
You can let PHP know that FormData element is an array
formData.append('new_override_arr[]', new_override_arr);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: you must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.