I have two JavaScript classes:
function Sensor(sensorNumber, name, m, b, selected) {
"use strict";
this.sensorNumber = sensorNumber;
this.name = name;
this.m = m;
this.b = b;
this.selected = selected;
}
The Chart class below contains an Array of the Sensor class above, some variables, and a timeSpan class:
function Chart(index, allsensors) {
"use strict";
this.chartName = $("#newChartName").val();
this.chartNumber = index;
this.sensorsArray = allsensors;
this.time = new TimeSpan();
}
I send the "chart" object variable to PHP via Jquery AJAX:
function obtainChartData(chart) {
"use strict";
$.ajax({
url: 'server/ExtractTelemetry.php',
type: "POST",
data: JSON.stringify(chart),
success: function (msg) {
alert(msg);
}
});
}
PHP Receives it, and this is where I'm stuck. I need to obtain the "this.Selected" for each element in the sensor object array.
<?php
$json = file_get_contents('php://input');
$chart = json_decode($json);
echo $startTime = $chart->time->startSec." "; //CORRECT
echo $endTime = $chart->time->endSec." "; //CORRECT
echo $chartName = $chart->chartName." "; //CORRECT
echo $chartNumber = $chart->chartNumber." "; //CORRECT
for(...) {
echo $allSensors = $chart->allSensors[someIndexValue]->selected; //why does this not work??
}
?>
UPDATE:
Here is the PHP Error output
JSON output(shortened but should be enough info):
object(stdClass)#1 (4) {
["chartName"]=> string(7) "Chart#1"
["chartNumber"]=> int(1)
["sensorsArray"]=> object(stdClass)#2 (44) {
["B0"]=> object(stdClass)#3 (5) {
["sensorNumber"]=> int(0)
["name"]=> string(10) "SRBUS(mV)"
["m"]=> string(6) "1.2811"
["b"]=> string(8) "-4.1559"
["selected"]=> bool(false)
}
["B1"]=> object(stdClass)#4 (5) {
["sensorNumber"]=> int(1)
["name"]=> string(10) "SRBUS(mA)"
["m"]=> string(6) "0.6137"
["b"]=>...

$chart->sensorsArray[someIndexValue]->selected?var_dump($chart);and looking at its actual structure.jsonstring passed to the server.