Now this is a pretty simple question, but due to my lack of jQuery knowledge I have to ask this..
In JS I have this variable, which is an array of marker data for Google Maps:
var Locations = {
1: {
info: '1. New Random info and new position',
lat: -37,
lng: 124.9634
},
2: {
info: '2. New Random info and new position',
lat: 70,
lng: 14.5144
},
3: {
info: '3. New Random info',
lat: 30,
lng: 24.5144
},
4: {
info: '4. New Random info',
lat: 34,
lng: 26.5144
},
5: {
info: '5. 55555. Added',
lat: -37,
lng: 0
}
};
I then have an ajax call to retrieve a new array of locations with PHP. The PHP looks like this example (note that I echo 3 pieces of data delimited by | ):
$arrayccordinates = array();
$countercords = 0;
echo 'Data1 |';
echo 'Data2 |';
foreach ($results as $result) {
$countercords = $countercords + 1;
$arrayccordinates[] = array( $countercords => array( 'info' => $infos, 'lat' => $latdata, 'lng' => $lngdata )
);
}
echo json_encode($arrayccordinates);
Here is the ajax call. Here I split the 3 data pieces up and the locations array is found in arr[2].:
//Ajax code
var interval = 5000; // 5000 ms = 5 secs
function doAjax() {
jQuery.ajax({
type: 'POST',
url: '/codes/LiveVisitsStats/postlivecounter.php',
dataType : 'html',
success: function (data) {
var arr = data.split('|');
jQuery('#counterint').html(arr[0]);
jQuery('#extrainfoscounter').html(arr[1]);
jQuery('#testdiv').html(arr[2]);
var newlocations = arr[2];
},
complete: function (data) {
// Schedule the next
setTimeout(doAjax, interval);
}
});
}
Now, I have tested this and it doesn´t seem to work. The array from PHP stored in "newlocations" variable does not seem to work as the original "Locations" variable. I have really no clue what I´m doing wrong, though I suspect my use of json_encode is completely wack..
data.key1or the index likedata[0].innerKey