I am trying to use a Dojo (ajax) table on my page that has detail rows in which I want to draw detail tables. The tables have a format event which calls formatDetail. In this event I would like to build a simple table using JSON data.
My problem is how do I use PHP to create the JSON data object so that my formatDetail javascript can use it?
My test code so far is, in the header:
function formatDetail(inWatchId, inRowIndex) {
alert("Length is: " + myJSON.length);
}
And in the body of the page:
$stmt = sqlsrv_query($connection,$query);
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC))
{
$arr[] = $row;
}
$objJSON = '{"sample":'.json_encode($arr).'}';
echo "<script>var myJSON = $objJSON;</script>";
When I try this, the js alert displays "Length is undefined"
What am I doing wrong?