我有一个Jquery数组,它被发布到PHP页面——这是数组之一的例子
array(3) {
["updatid"]=>
string(7) "jammey90"
["update_rw"]=>
string(1) "C"
["access"]=>
array(1) {
[3]=>
array(20) {
[0]=>
string(2) "BP"
[1]=>
string(2) "OL"
[2]=>
string(0) ""
[3]=>
string(0) ""
[4]=>
string(0) ""
[5]=>
string(0) ""
[6]=>
string(0) ""
[7]=>
string(0) ""
[8]=>
string(0) ""
[9]=>
string(0) ""
[10]=>
string(0) ""
[11]=>
string(0) ""
[12]=>
string(0) ""
[13]=>
string(0) ""
[14]=>
string(0) ""
[15]=>
string(0) ""
[16]=>
string(0) ""
[17]=>
string(0) ""
[18]=>
string(0) ""
[19]=>
string(0) ""
}
}
}
在运行Update语句之前,我试图将它们分离为变量$userid
、$rw
和$access
。我试过
foreach( $_POST as $stuff ) {
if( is_array( $stuff ) ) {
foreach( $stuff as $thing ) {
echo $thing
}
} else {
echo $stuff;
}
}
但在回声中我得到的是CCD_ 4。我做错了什么?
Jquery
$(document).ready(function() {
$('[name="update_user_record"]').unbind('click').click(function() {
var datapost = {};
datapost['updatid'] = $(this).parent().parent().find('[name="userid"]').val();
datapost['update_rw'] = $(this).parent().parent().find('[name="rw"]').val();
datapost['update_extra'] = $(this).parent().parent().find('[name="extra"]').val();
datapost['update_access'] = $(this).parent().parent().find('[name="access"]').val();
$(this).parent().parent().find('input[name^="access"]').each(function(){
if ( $(this).attr('name').indexOf('O') === -1 ) {
datapost[$(this).attr('name')] = $(this).val();
}
});
$.ajax({
type:'POST',
url:'update_records.php',
data: datapost,
success: function (Response) {
alert(Response);
}
})
});
});
感谢
在第一个foreach中需要另一个foreach。。试试看,让我知道。
foreach( $_POST as $stuff ) {
if( is_array( $stuff ) ) {
foreach( $stuff as $thing ) {
foreach( $thing as $t ) {
echo $t . '<br />';
}
}
} else {
echo $stuff . '<br />';
}
}
尝试这个
extract($_POST); //it will separate the all the field names to a varialbles