In my test.php which is called by an ajax
在我的test.php中,由ajax调用
I have this
我有这个
echo json_encode($month);
echo json_encode($sum);
and then the result is
然后结果是
Then in my js file (part of my ajax)
然后在我的js文件中(我的ajax的一部分)
success: function (dataofconfirm) {
var $data = dataofconfirm;
alert($data);
}
The above result is caused by my alert, right? so moving on how can i split them by their group let's say like the one below
以上结果是由我的警报引起的,对吧?所以继续我们如何将他们分组,让我们说如下
var $months = (The Jun to November);
var sums = (the 3288 something and so on);
I tried splice but failed.
我尝试拼接但失败了。
Thanks.
谢谢。
1 个解决方案
#1
0
Why don't you just return one json object, containing your months and values?
为什么不直接返回一个包含月份和值的json对象?
$data = Array();
$data[0] = array("month" => "Jun", "value" => 1234546);
$data[1] = array("month" => "Jul", "value" => 987654);
.
.
etc
echo json_encode($data);
Then on client side:
然后在客户端:
success: function (dataofconfirm) {
var data = dataofconfirm;
for(var x = 0; x < data.length; x++
{
var month = data[x].month;
var value = data[x].value;
}
This way you can use each month and value pare separately or combine it in a month and value array as needed.
这样,您可以单独使用每个月和值的值,或者根据需要将它组合在一个月和值数组中。
#1
0
Why don't you just return one json object, containing your months and values?
为什么不直接返回一个包含月份和值的json对象?
$data = Array();
$data[0] = array("month" => "Jun", "value" => 1234546);
$data[1] = array("month" => "Jul", "value" => 987654);
.
.
etc
echo json_encode($data);
Then on client side:
然后在客户端:
success: function (dataofconfirm) {
var data = dataofconfirm;
for(var x = 0; x < data.length; x++
{
var month = data[x].month;
var value = data[x].value;
}
This way you can use each month and value pare separately or combine it in a month and value array as needed.
这样,您可以单独使用每个月和值的值,或者根据需要将它组合在一个月和值数组中。