dongwu3596 2018-11-03 14:07
浏览 41

在PHP中检索JSON的问题

My Javascript sends an array in JSON to dbinsert.php

function SendTableToPHP() {
  //Store HTML Table Values into Multidimensional Javascript Array Object
  var TableData;
  TableData = storeTblValues()

  function storeTblValues() {
    var TableData = new Array();
    $('#itemtable tr').each(function(row, tr) {
      TableData[row] = {
        "ritem": $(tr).find('td:eq(0)').text(),
        "rqnty": $(tr).find('td:eq(1)').text(),
        "rbale": $(tr).find('td:eq(2)').text(),
        "ramt": $(tr).find('td:eq(3)').text(),
        "rrmk": $(tr).find('td:eq(4)').text(),
      } //tableData[row]
    });

    TableData.shift(); // first row will be empty - so remove
    //console.log(TableData);
    return TableData;
  }

  var Data;
  Data = $.toJSON(TableData);
  console.log(Data);

  $.ajax({
    type: "POST",
    url: "dbinsert.php",
    data: "pTableData=" + Data,
    success: function(msg) {
      alert(msg) //return value stored in msg variable "success";
    } //success
  });
};

The output result also alerts showing the response from dbinsert.php: Output Showing json created

<?php
  // Unescape the string values in the JSON array
  $tableData = stripcslashes($_POST['pTableData']);

  // Decode the JSON array
  $tableData = json_decode($tableData,TRUE);

  // now $tableData can be accessed like a PHP array
  echo $tableData[1]['ritem'];
  echo $tableData[2]['ritem'];
  echo $tableData[3]['ritem'];

  $dat = $_POST['podat'];
  echo $dat;
?>

However the output is showing only date ($dat) and what i want to display array from that json. i need to insert data in database from that array thats why i want to check if array isdisplaying ok or not.

Here is the source code: https://www.fourfront.us/blog/store-html-table-data-to-javascript-array

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥170 如图所示配置eNSP
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改
    • ¥20 wireshark抓不到vlan
    • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
    • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
    • ¥15 stata安慰剂检验作图但是真实值不出现在图上
    • ¥15 c程序不知道为什么得不到结果