I do an AXAX post like so:
$.ajax({
type : 'POST',
url : 'formprocess.php',
data: {formtype: 'load_all_names'},
dataType : 'json',
encode : true
}).done(function(data) {
});
The PHP page it posts to is formprocess.php, which looks like:
$return = array();
$return['names'][0]['name'] = 'Tom';
$return['names'][0]['age'] = 20;
$return['names'][1]['name'] = 'Dick';
$return['names'][1]['age'] = 30;
$return['names'][2]['name'] = 'Harry';
$return['names'][2]['age'] = 40;
echo json_encode($return);
Now, how do I get, for example, Harry's age?
$.ajax({
type : 'POST',
url : 'formprocess.php',
data: {formtype: 'load_all_designs'},
dataType : 'json',
encode : true
}).done(function(data) {
alert(data.names[2].age); // Not working
});
- EDIT: My formprocess.php file does echo the array.