I am trying to get the string "Name n" out of the php array $F[], which is randomised inside the function DataInit1(), and put it in a div inside my html file. However, the PHP file cannot be changed because the arrays are randomised and used to plot a series of graphs.
PHP file:
<?php
$Return = array();
$P = array();
$S = array();
$F = array();
$P[] = [0];
$S[] = [[0.00,111],[0.50,104.74],[1.00,91.29],[1.50,93.28],...];
$F[] = "Name 1";
$P[] = [0];
$S[] = [[0.00,199],[0.50,84.06],[1.00,82.43],[1.50,83.02],...];
$F[] = "Name 2";
for($i=0; $i<count($P); $i++)
{
$Return[] = $P[$i];
$Return[] = $S[$i];
$Return[] = $F[$i];
}
die(json_encode($Return));
?>
HTML file:
<div id="GRAPH">
<div id="title"><h1 id='graphtitle'></h1></div>
<h1 id='GraphNum'></h1>
<div id="chart"></div>
<h1 id='PointNum'></h1>
</div>
The string should be placed in the "ARRAY $F" as shown below in the JS file:
function DataInit1()
{
$.ajaxSetup({cache: false, async: false});
$.getJSON("data1.php",
function(Data1)
{
SeriesList = [];
CurrentGraph.Series = 0;
for(var i=0; i<Data1.length; i+=3)
{
var P = Data1[i+0];
var S = Data1[i+1];
var F = Data1[i+2];
var NewSeries = new SeriesClass(P,S,F);
NewSeries.SeriesNumber = (i/3)+1;
SeriesList.push(NewSeries);
}
}
);
for(var i=SeriesList.length-1; i>0; i--)
{
var j = Math.floor(Math.random() * (i+1));
var x = SeriesList[i];
SeriesList[i] = SeriesList[j];
SeriesList[j] = x;
}
}
........
function Title()
{
$("#title").show();
$.ajaxSetup({cache: false, async: false});
$.getJSON("data1.php",
function(data)
{
var name = ARRAY $F;
});
$("#graphtitle").html(name);
}
Any other idea or suggestion on this issue will be very welcome. Thank you.
UPDATE:
Based on the suggestion by ironpilot. Could the solution be something like this?:
function Title()
{
$("#title").show();
$.ajaxSetup({cache: false, async: false});
$.getJSON("CurrentGraph.Series",
function(data)
{
var titleGraph = (json_decode($F, true));
var name = data.titleGraph[0];
$("#graphtitle").html(name);
});
}