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