0

How do you process a javascript array in PHP, when you're posting it. Here's what I am doing:

$(".action_btn").live('click', function() {
            var friends = new Array();
            $(this).parents('.friends_rec').find('input:checked').each(function(k) { friends[k] = $(this).val(); });
            var comment = $(this).parents('.friends_rec').find('textarea').val();

                $.post("update.php",
                    { uid: <?php echo $_SESSION['uid']; ?>, mid: <?php echo $_GET['mid']; ?>, friends: friends, comment: comment },
                    function() {

                    });
            }
        });

Question is, in update.php, what should I do to iterate this friends array?

2
  • Have a look at the json_decode function in PHP. Commented Apr 30, 2011 at 18:38
  • yes I have, will it work if I just do json_decode of the friends? Commented Apr 30, 2011 at 19:04

1 Answer 1

-1

try to use

$.post("update.php",
{ uid: <?php echo $_SESSION['uid']; ?>, mid: <?php echo $_GET['mid']; ?>, 'friends[]': friends, comment: comment },
function() {

});

or you can use friends.join("#"), for example and in php-script explode() func

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.