作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在这里,我得到了两个 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/
使用登录后,我想吐出用户名。 但是,当我尝试单击登录按钮时, 它给了我力量。 我看着logcat,但是什么也没显示。 这种编码是在说。 它将根据我在登录屏幕中输入的名称来烘烤用户名。 不会有任何密码。
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎是题外话,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a min
我是一名优秀的程序员,十分优秀!