我想通過AJAX jQuery中 我阿賈克斯PHP頁面上發送一些值存儲在PHP數組或PHP會話值,並希望將它們存儲存儲值PHP數組/會議通過AJAX jQuery中
問題:每次陣列/會話返回最新SENT值,不是我送
我想,以前發送的值應該在陣列或會話保留以前的值
我的代碼如下
JS文件代碼
$.ajax({
url: "http://domain.com/ajax.php",
type:"POST",
data: { name : nname ,
clas : nclass ,
rows : nrows ,
cols : ncols ,
types : ntype ,
check : ncheck ,
count : ncldiv
},
success: function(data){
alert(data);
}
});
php文件
<?php
session_start();
$_SESSION['feilds'] = array();
$type = $_POST['types'];
$name = $_POST['name'];
$class = $_POST['clas'];
$rows = $_POST['rows'];
$cols = $_POST['cols'];
$check = $_POST['check'];
$count = $_POST['count'];
$output_string = array('TYPE'=>$type,'NAME'=>$name,'CLASS'=>$class,'ROWS'=>$rows,'COLS'=>$cols,'REQUIRED'=>$check);
array_push($_SESSION['feilds'] , $output_string);
print_r($_SESSION['feilds']);
?>
它將覆蓋在會議之前存儲的值。因爲你用$ _SESSION ['feilds'] = array()'刪除前一個數組並創建一個新的空數組,並在其中推送新數據,因此使用相同的鍵 –
覆蓋值。 – Gntem