我像这样做一个AXAX帖子:
$.ajax({
type : 'POST',
url : 'formprocess.php',
data: {formtype: 'load_all_names'},
dataType : 'json',
encode : true
}).done(function(data) {
});
它发布的PHP页面是formprocess.php,如下所示:
$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);
现在,我如何得到,例如,哈利的年龄?
$.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
});