My php code produce something like that with this link getPower.php?year=2012&country=tr
"Kasan":[[1,50]]
"Tasan":[[1,51],[2,52],[3,52]]
"Hasan":[[1,50]]
"Masan":[[1,51],[2,52],[3,52]]
With this code;
$row = $result->fetch_assoc();
echo json_encode($row['teamName']). ":" ;
putPowerbyTeam($db,$row['teamID'],$year); //End with echo "json_encode($returnArray);"
echo "\n";
And I’m trayin to convert them into JavaScript Object with this code;
$.ajax({type: "GET",
url: "getPower.php",
data: {year : "year", country : "country"},
success: function(JSONText) {
var lines = JSONText.split('\n');
$.each(lines,function(lineNo,line)
{
var mainItems = line.split(':');
chart.series[lineNo].name = jQuery.parseJSON(eval(mainItems[0]));
chart.series[lineNo].setData(jQuery.parseJSON(eval(mainItems[1])), true);
});
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
I’m an error which say cannot split the null. So, null is returned but i can’t be sure any part of this javascrip code.
So, why null is returned?
What can i do?
Is the rest is good?
Don’t try to build your JSON with multiple
echoandjson_encode. Use one big associative array and thenecho json_encode(array).Something like this :