我有一個頁面中,我需要重新加載的緯度和經度刷新谷歌地圖。我做到這一點使用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