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'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作