[英]Ajax - PHP associative array into jquery associative array via ajax/json
[英]java script array of objects to php via ajax (jquery) and json
這是javascript代碼:
var jsonData = JSON.stringify(testObj);
$.ajax({
url: '../php/functions/spesific_field_set.php',
type: 'post',
data: {fieldObjArray: jsonData, tableName: fieldTableName}
}).always(SpesificPropertiesSet);
這是PHP:
$updates = mysql_real_escape_string($_POST['fieldObjArray']);
$updates = json_decode($updates, true);
$tableName = mysql_real_escape_string($_POST['tableName']);
echo $updates;
testObj是一個對象數組,我應該如何將它傳遞給php? 如何在php端訪問這個對象數組中的數據?
謝謝!!
這是PHP文件。 這應該向您展示如何訪問通過AJAX發送的$updates
。
$updates = $_POST['fieldObjArray'];
$updates = json_decode($updates, true);
$tableName = $_POST['tableName'];
echo $updates; // this is an array so this would output 'Array'
foreach ($updates as $key => $value) {
echo 'Key: '.$key.' Value: '.$value.'<br />'; // to access this, just use $updates['key']
}
// example
echo $updates['something'];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.