PHP (processing.php):
$responce["x"] = 0;
$responce["y"] = [1, 3];
echo json_encode($responce);
javascript:
$.get("processing.php", function(data){
alert("Data: " + data)
});
Output (alert):
Data: {"x":0,"y":["1","3"]}
I need to access the variable x, and the array y in javascript ?!!
Parse the JSON string with
$.parseJSON().Then, access
data.x.Alternatively, you can set the
dataTypetojsonor use$.getJSON()which will automatically do it.