I've been working on this for quite a while, and I've read TONS of posts on SO trying to figure out how I need to do this, and I can't seem to get it to work. I'm thinking it must be some aspect of the way I've coded things. So downvote away, but hopefully some kind soul will help me out.
I've tested using jsonlint, which comes back valid. I'm getting a response from the server with the values, I just can't seem to get anything in the browser other than when I just alert(response);. I need to be able to access the value of "cat_id_PK" and the other elements separately to loop through and display them in html table cells.
JSON:
{
"income": [
{
"cat_id_PK": 14,
"cat_name": "test1",
"cat_amount": "100.00"
},
{
"cat_id_PK": 15,
"cat_name": "test2",
"cat_amount": "200.00"
},
{
"cat_id_PK": 34,
"cat_name": "test3",
"cat_amount": "300.00"
},
"expense": [
{
"cat_id_PK": 14,
"cat_name": "tes41",
"cat_amount": "400.00"
},
{
"cat_id_PK": 15,
"cat_name": "test5",
"cat_amount": "500.00"
},
{
"cat_id_PK": 34,
"cat_name": "test6",
"cat_amount": "600.00"
}
]
}
PHP
$array = array(
'income' => $income,
'expense' => $expense,
'recurring' => $recurring
);
echo json_encode($array);
JQUERY
var request = $.ajax({
type: "POST",
url: 'inc/functions.php',
dataType: "JSON",
data: {action: "display_categories", cur_month:cur_month}
});
request.done(function(response){
//for each element put values in <td></td> tags.
});