这是 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'];
关于php - java脚本对象数组通过ajax(jquery)和json到php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12657516/