JavaScript数组传递到PHP数组中
问题描述:
如何在PHP中处理JavaScript数组,当您发布它时。 下面是我在做什么:JavaScript数组传递到PHP数组中
$(".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() {
});
}
});
的问题是,在update.php,我应该怎么做才能遍历这个朋友阵列?
答
尝试使用
$.post("update.php",
{ uid: <?php echo $_SESSION['uid']; ?>, mid: <?php echo $_GET['mid']; ?>, 'friends[]': friends, comment: comment },
function() {
});
,或者您可以使用friends.join( “#”),例如在PHP脚本爆炸()FUNC
看一看在PHP中的json_decode功能。 – Gazler 2011-04-30 18:38:50
是的,如果我只是做朋友的json_decode,它会工作吗? – alexander 2011-04-30 19:04:17