gpt4 book ai didi

javascript - 想要提醒第二个 json 数据数组

转载 作者:行者123 更新时间:2023-12-03 08:01:35 25 4
gpt4 key购买 nike

在这里,我得到了两个 json 数组。我确实在第一个 json 数据在 ajax 中发出警报后退出。但是当我要警告第二个 json 数据时,它显示“未定义”。那么,第二个json数据的alert值如何获取呢?

我的代码就像,

$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();

ajax 调用就像,

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 (){}
});

(更新):在这里,如果我不调用 exit(),我就无法获取 ajax 中的值,那么问题出在哪里呢?

最佳答案

您应该删除第一个 exit(); 或删除两者,我猜您的代码应该是这样的:

$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);

或者尝试使用多维数组,如下面评论中提到的@Ohgodwhy:

$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;

希望这有帮助。

关于javascript - 想要提醒第二个 json 数据数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34558737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com