Reputation: 357
Here, I am getting two array of json. I did exit after first json data to alert in ajax. But when I am going to alert second json data, it shows "undefined". So, How can be alert value of second json data?
My code is like,
$data1['month_result'] = $user_wise_performance;
$data1['total_point'] = $total_point;
$data1['total_earn_point'] = $total_earn_point;
echo json_encode($data1);
exit();
$data2['week_month_result'] = $user_wise_performance;
$data2['week_total_point'] = $total_point;
$data2['week_total_earn_point'] = $total_earn_point;
echo json_encode($data2);
exit();
And ajax call is like,
jQuery.ajax({
url: "<?php echo base_url(); ?>grade_tasks/emp_performance",
data:'',
type:"GET",
dataType: "json",
success:function(data){
alert(data.total_earn_point);
alert(data.week_total_earn_point); //This is not printing the value.
},
error:function (){}
});
(Updated): Here, if I am not calling exit(), I am not getting the value in ajax, So what can be the problem?
Upvotes: 0
Views: 46
Reputation: 67505
You should remove the first exit();
or remove the both, i guess that your code should be like :
$data1['month_result'] = $user_wise_performance;
$data1['total_point'] = $total_point;
$data1['total_earn_point'] = $total_earn_point;
$data1['week_month_result'] = $user_wise_performance;
$data1['week_total_point'] = $total_point;
$data1['week_total_earn_point'] = $total_earn_point;
echo json_encode($data1);
Or try to use multidimensional array like @Ohgodwhy mentioned in comment bellow :
$data =
[
'data1' => [
'month_result' => $user_wise_performance,
'total_point' => $total_point,
'total_earn_point' => $total_earn_point
],
'data2' => [
'week_month_result' => $user_wise_performance,
'week_total_point' => $total_point,
'week_total_earn_point' => $total_earn_point
]
];
echo $data;
Hope this helps.
Upvotes: 1