How do I pass PHP string via ajax into variable array??? ( I´m a jquery noob..)

How do I pass PHP string via ajax into variable array??? ( I´m a jquery noob..)

Hello,

I´m fiddling with a Google Map script and I´m trying to update the map dynamically using ajax.
On pageload the map initiates with an array of coordinates as markers/locations.

The locations data is defined in JS like this example:

  1. var locations = [
  2.       ['Bondi Beach', -33.890542, 151.274856, 4],
  3.       ['Coogee Beach', -33.923036, 151.259052, 5],
  4.       ['Cronulla Beach', -34.028249, 151.157507, 3],
  5.       ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
  6.       ['Maroubra Beach', -33.950198, 151.259302, 1]
  7.     ];

Now, how do I use Ajax to receive a new array from PHP and store the output as JS variable array?

Here is my ajax script:

  1. var interval = 5000;  // 1000 = 1 second, 3000 = 3 seconds
  2. function doAjax() {
  3.     jQuery.ajax({
  4.             type: 'POST',
  5.             url: '/codes/LiveVisitsStats/postlivecounter.php',
  6.             dataType : 'html',
  7.             success: function (data) {
  8.             var arr = data.split('|');
  9.                     jQuery('#counterint').html(arr[0]);
  10.                     jQuery('#extrainfoscounter').html(arr[1]);   
  11.                     jQuery('#testdiv').html(arr[2]);         
  12.             
  13.             var LocationData2 = arr[2];  

  14.             },
  15.             complete: function (data) {
  16.                     // Schedule the next
  17.                     setTimeout(doAjax, interval);
  18.             }
  19.     });
  20. }
  21. setTimeout(doAjax, interval);


Her is an example of my PHP  postlivecounter.php :

  1. $ayyarutest = ' [  ["Bondi Beach", -33.890542, 151.274856, 4],
  2.       ["Coogee Beach", -33.923036, 151.259052, 5],
  3.       ["Cronulla Beach", -34.028249, 151.157507, 3],
  4.       ["Manly Beach", -33.80010128657071, 151.28747820854187, 2],
  5.       ["Maroubra Beach", -33.950198, 151.259302, 1]  ] ';
  6.       
  7. echo $ayyarutest.' |';