2012-03-16 27 views
1

Googleマップapiを使用して2か所の距離を保存する機能がありました。それらの結果はvolunteerDistに格納され、定義されたjid配列があります。 5行目のDocument.writeは配列内の各要素の内容を示していました。さて、ボランティアディストリクトのObject.prototypeに警告するとobject arrayと言います。しかし、私が$ .ajaxを呼び出し、volunteerDistをデータに転送して警告すると(下に示すように)、未定義と成功を返します(データは保存されていますが、内容は未定義です)。どんな助け?おかげ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'); 
    } 
}); 
} 

アップデート:以下

は、それが今、同じデータ変数のマイtoDistance.php

<?php 
    $distance=array(); 
    $volunteerid=array(); 
    if(empty($_GET)){ 
     echo "Hello"; 
    } 
    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]; 
      "); 
     } 
    } 
?> 

答えて

1

です!それは他の範囲にある。

成功関数のdataは、サーバーが返したものです。それがあなたを混乱させるならば、別の名前を付けてください。

$.ajax({ 
    type:'POST', 
    url: 'toDistance.php', 
    data : ({ 
     distance:volunteerDist, 
     id:jid 
    }), 
    success: function(result){ // Data sent from the server. not the data above! 
     alert(result); 
     alert('worked'); 
    }, 
    error :function(jqXHR, textStatus, errorThrown) { 
     alert(errorThrown); 
    }, 
    complete : function(){ 
     alert('thanks'); 
    } 
}); 
+0

何も間違っていますか? @BrandonYoung。 –

+0

私は考えていません、このスクリプトに間違いはありません。あなたは、サーバーコードで新しい質問スレッドを開いておきたいかもしれません。 **このスクリプトは問題ありません!** – gdoron

+0

私の質問を編集してtoDistance.phpを追加しました。私はtoDistance.phpのLine 5でエコーしたものが '結果'に警告されていることに気付きました。 @BrandonYoung。 –