0

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側のオブジェクトのこの配列内のデータにどのようにアクセスする必要がありますか?

ありがとう!!

4

1 に答える 1

2

これはPHPファイルです。$updatesこれにより、AJAXを介して送信されたアクセス方法が示されます。

$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'];
于 2012-09-29T23:55:43.707 に答える