I'm creating an array in php and then using json_encode() before getting it with $.getJSON but it returns Undefined. If I send just one row to JS it working fine (json_encode($classes[0])) but when I try to send all the data it returns Undefined. Any ideas?
Here is a little of the array which is generated by querying the database and returning the results...
Array
(
[0] => Array
(
[Record_Type] => S
[Convention_ID] =>
[Event_ID] => 19030145
[Sponsor_ID] => Google
[Course_ID] => 2837199
[Last_Modified_Date_Time] => DateTime Object
(
[date] => 2019-02-25 10:03:36.000000
[timezone_type] => 3
[timezone] => US/Pacific
)
)
[1] => Array
(
[Record_Type] => S
[Convention_ID] =>
[Event_ID] => 19030111
[Sponsor_ID] => Google
[Course_ID] => 2837192
[Last_Modified_Date_Time] => DateTime Object
(
[date] => 2019-02-21 07:23:47.000000
[timezone_type] => 3
[timezone] => US/Pacific
)
)
here is the php minus the SQL statement...
$stmt = sqlsrv_query($conn, $sql);
$classes = array();
while( $class = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
$classes[] = $class;
}
echo $_GET['callback'] . '('.json_encode($classes).')';
and here is the Javascript which I'm using to get the JSON data...
$(function() {
$.getJSON("https://example/api/education.php?callback=?",
function(data) {
console.log(data);
}
);
});