我有一个页面中,我需要重新加载的纬度和经度刷新谷歌地图。我做到这一点使用AJAX,JS的功能是这样的:jQuery的Ajax响应文本没有完成
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
是一个全局变量JS存储从PHP文件的响应。如果我使用浏览器调用PHP文件的数据是完整的,我想要得到(posArrray[0],..,posArray[n])
,但如果我使用JS函数调用PHP,则JS变量仅保存(posArray[n-1],posArray[n])
,并且所有其他坐标仅在JS变量中丢失PHP脚本运行良好。
<?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;
?>
我不知道如果我回到在php文件不正确,我也试图与refresh=$.ajax({}).responseText;
的$回应,我也得到了相同的结果。
你说你应该得到一个纬度和经度的列表,你在php中的for循环似乎支持这个。然而,[FETCH_ASSOC](http://php.net/manual/en/mysqli-result.fetch-assoc.php)仅返回当前记录,而不是整个记录集的阵列。 – jwatts1980 2011-02-11 21:46:14