doumei8258 2012-09-29 23:50
浏览 62
已采纳

java脚本数组通过ajax(jquery)和json到php

Here is javascript code:

var jsonData = JSON.stringify(testObj);
            $.ajax({
              url: '../php/functions/spesific_field_set.php',
              type: 'post',
              data: {fieldObjArray: jsonData, tableName: fieldTableName}
              }).always(SpesificPropertiesSet);

and here is the php:

$updates = mysql_real_escape_string($_POST['fieldObjArray']);
$updates = json_decode($updates, true);
$tableName = mysql_real_escape_string($_POST['tableName']);

echo $updates;

What testObj is an array of object, how should I pass it to the php? and how should I access the data within this array of objects on php side?

thanks!!

  • 写回答

1条回答 默认 最新

  • doureng5668 2012-09-29 23:55
    关注

    This is the PHP file. This should show you how you can access $updates that was sent through 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'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?