0
$('#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?

4
  • Did you tried to put array_a in brackets - data: { "array_a" : values_array }? Commented May 13, 2012 at 11:43
  • What is the output of print_r($_POST) ? Commented May 13, 2012 at 11:45
  • Array ( ), as expected Commented May 13, 2012 at 11:47
  • check out what's the content of values_array after each() with console.log() Commented May 13, 2012 at 11:47

2 Answers 2

6

Change:

values_array.push = $(this).val();

to:

values_array.push($(this).val());

That should do the trick :)

Sign up to request clarification or add additional context in comments.

Comments

1

.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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.