I am in the process of developing a basic application where the user can interact with a button to retrieve a JSON object from the database. The object's structure is displayed below. However, the system is failing to recognize the object, resulting in execution errors. Any insights on why this might be occurring?
Here is the array response from PHP being passed to JavaScript
array(2) (
[success] => (bool) true
[cnt] => array(2) (
[2014-11-28] => array(2) (
[visits] => (string) 1115
[searches] => null
)
[2014-11-29] => array(2) (
[visits] => (string) 493
[searches] => 0
)
)
)
JSON object structure
{
"success":true,
"cnt":{
"2014-11-28":{
"visits":"1115",
"searches":null
},
"2014-11-29":{
"visits":"493",
"searches":0
}
}
}
Snippet of the function responsible for parsing the object
$.post(JOBK.ajaxurl, data, function (resp) {
if (resp.success) {
// Append rows
$.each(resp.cnt, function (dateCol) {
$.each(dateCol, function (visitsCol, searchesCol) {
// Insert a row in the table at row index 0
var newRow = tableRef.insertRow(tableRef.rows.length);
});
});
}
}, 'json');
});