$('#button').live('click', function () {
values_array = [];
$('.field').each(function () {
values_array.push = $(this).val();
});
$.ajax({
url: 'page.php',
data: {
array_a: values_array
},
type: 'POST',
success: function (data) {
$('#div').html(data);
}
});
});
//page.php
echo $_POST['array_a'] . "<br/>"; //The line break echos, but nothing else
A.) Do I need to iterate through each class with $.each in order to create a proper array, and
B.) Why doesn't php echo it?
thecodedeveloper.com
3,2505 gold badges40 silver badges69 bronze badges
asked May 13, 2012 at 11:40
Norse
5,75716 gold badges54 silver badges87 bronze badges
2 Answers 2
Change:
values_array.push = $(this).val();
to:
values_array.push($(this).val());
That should do the trick :)
answered May 13, 2012 at 11:47
billyonecan
20.3k9 gold badges45 silver badges66 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
.push is a method which you have used like a property try instead
values_array = [];
$('.field').each(function() {
values_array.push($(this).val());
});
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/push
answered May 13, 2012 at 11:50
Rafay
31.1k5 gold badges71 silver badges106 bronze badges
Comments
default
array_ain brackets -data: { "array_a" : values_array }?print_r($_POST)?Array ( ), as expected