I have a php session file with name 'script1.php' which contains '$position' array. I want to access the value of this array in javascript file. I tried using this "$.get('script1.php', function ( data ) { var x = data;});" command and in 'data' variable i get {"Longitude": 12.917186, "Latitude": 50.831356} this kind of result , but I need to access only integer, how can i access the integer value. I have uploaded the php code. can someone please help me how to solve this problem i am new to the php.
<?php
// Start the session
session_name("mysession");
session_start();
if(isset($_SESSION["i"])){
$i = $_SESSION["i"];
}
else{
$i = 0;
}
// Set session variables
$position = array
(
array(50.831118, 12.916574),
array(50.831118, 12.918574),
array(50.831356, 12.917186),
array(50.831604, 12.917834),
array(50.831763, 12.918172),
array(50.831916, 12.918603),
array(50.832825, 12.918413),
array(50.833206, 12.918303),
array(50.832825, 12.918413),
array(50.831916, 12.918603),
array(50.831763, 12.918172),
array(50.831604, 12.917834),
array(50.831356, 12.917186),
array(50.831118, 12.918574),
array(50.831118, 12.916574)
);
echo '{"Longitude": '.$position[$i][1].', "Latitude": '.$position[$i]
[0].'}';
$i++;
if($i > count($position)){
$i = 0;
}
$_SESSION["i"] = $i;
JavaScript code
$.get('script1.php', function ( data )
{
var x = data;
});
value stored in data variable {"Longitude": 12.917186, "Latitude": 50.831356}