1
私は以下のajax実装を持っていました。今、toDistance.phpで距離とIDを取得するにはどうすればいいですか?下のコードを貼り付けて、データベースにデータを追加しませんでした。なにが問題ですか?以下はPHPはAJAXから値を取得
function getABC(){
for(s=0;s<length;s++){
volunteerlocation = new GLatLng(jlat[s], jlng[s]);
volunteerDist[s] = (Math.round((eventlocation.distanceFrom(volunteerlocation)/1000)*10)/10);
document.write(volunteerDist[s] + '<br> ');
document.write(jid[s] + '<br> ');
}
alert(Object.prototype.toString.call(volunteerDist));
$.ajax({
type:'POST',
url: 'toDistance.php',
data : ({
distance:volunteerDist,
id:jid
}),
success: function(data){
alert(data);
alert('worked');
},
error :function(jqXHR, textStatus, errorThrown) {
alert(errorThrown);
},
complete : function(){
alert('thanks');
}
});
}
あなたはPOSTリクエストでデータを送信し、代わりに$ _POST
別の$ _GETからPHPでそれを取得しようとしている私のtoDistance.php
<?php
$distance=array();
$volunteerid=array();
if(empty($_GET)){
}
else{
$distance = isset($_GET['distance']) ? $_GET['distance'] : 0;
$volunteerid = isset($_GET['id']) ? $_GET['id'] : 0;
$connect = mysql_connect("localhost","root","");
mysql_select_db("mapping");
for($i=0;$i<$distance.length;$i++){
$updateDistance = mysql_query("
UPDATE volunteerbio
SET volunteerDistance = $distance[$i]
WHERE volunteerID = $volunteerid[$i];
");
}
}
?>
大丈夫..しかし、今、どのように「長さ」は、それが配列である距離の長さだけであることにより、未定義の定数であり、来ますか? –
私はこれを試みたが、それは未定義のオフセットを言う? –
try:if(is_array($ distance)){... for loop ...} count()は配列以外の$ distanceに1を返しますので、未定義のオフセットを取得しています – galchen