I have a page in which I have to reload latitudes and longitudes to refresh a Google map. I do this using ajax, the JS function is this:
function refreshMap(idCamiones)
{
$.ajax({
type: "GET",
async: false,
url: "refresh.php",
data: "idCamiones="+idCamiones,
contentType: "application/x-www-form-urlencoded",
success : function(text)
{
refresh = text;
}
});
//Borramos todos los marcadores actuales
for (i in markersArray) {markersArray[i].setMap(null);}
markersArray.length=0;
//generamos un array con las latitudes en pares y las longitudes en nones.
posArray=refresh.split(",");
for(i=0;i<=posArray.length;i=i+2)
{
addMarker(2,posArray[i],posArray[i+1]);
}
}
refresh
is a global JS variable which stores the response from the PHP file. If I call the PHP file using the browser the data is complete, I'm supossed to get (posArrray[0],..,posArray[n])
but if I call the PHP using the JS function the JS variable only saves (posArray[n-1],posArray[n])
and all the other coordinates are missing just in the JS variable my PHP script works well.
<?php
include_once("conexion.php");
$idCamiones=$_GET['idCamiones'];
$reponse='';
$query="SELECT * from datos INNER JOIN dbo.eventos ON eventos.codigo=datos.codigo where id IN (
Select max(id) from datos where camion in (".$idCamiones.") group by serie) order by serie";
$bD=new COM("ADODB.Recordset");
$bD->Open($query,$conn);
$busData=fetch_assoc($bD);
$bD->close();
for($i=0;$i<sizeof($busData);$i++)
{
$response.=$busData[$i]['latitud'].",".$busData[$i]['longitud'].",";
}
echo $response;
?>
I dont know if I'm returning the $response in the php file incorrectly, I also tried with refresh=$.ajax({}).responseText;
and I get the same results.