In php am urmatorul cod:
Cod: Selectaţi tot
$element1 = fnc1 ($var1, $var2); // returneaza un string 'test test test'
$element2 = fnc2 ($var1, $var2); // returneaza un string '["test", "test", "test"]'
$element3 = fnc3 ($var1, $var2); // returneaza un string '{name: 'test', data: [1,2,3,4,]}' (nu stiu cat de utile sunt { } )
echo json_encode(
array("element1" => "$element1",
"element2" => "$element2",
"element3" => "$element3")
);
// echo json_encode returneaza:
{"element1": "test test test",
"element2": "[\"test\", \"test\", \"test\"]",
"element3": "{name: 'test', data: [1,2,3,4,] }"}
?>
Cod: Selectaţi tot
...
function (result) {
// result in consola arata: { element1: "test test test", element2: "["test", "test", "test"]", element3: "{name: 'test', data: [1,2,3,4,]}"}
var div1 = result.element1; // prima cheie o foloesc ca string
var chart1 = result.element2; // a doua cheie o folosesc ca un array de forma ['test', 'test', 'test']
var chart2 = result.element3; // a treia cheie o folosesc ca un array de forma [{ name: 'test', data: [1,2,3,4] }]
//pentru a transforma chart1 din string in array
chart1 = JSON.parse(chart1);
}
"{name: 'test', data: [1,2,3,4,] }"
intr-un array
[{ name: 'test', data: [1,2,3,4] }]
Multumesc!