1
아래에는 Google지도 API를 사용하여 두 곳의 거리를 저장하는 기능이 있습니다. 그 결과는 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];
");
}
}
?>
빈 경고가 표시되었습니다. 무엇이 잘못 되었습니까? –
@BrandonYoung. 나도 몰라,이 스크립트에는 아무 문제가 없다. 서버 코드와 함께 새로운 질문 - 스레드를 열어 볼 수도 있습니다. **이 스크립트는 괜찮습니다! ** – gdoron
나는 내 질문을 편집하고 toDistance.php를 추가했다. 나는 toDistance.php의 Line 5에서 에코 한 내용이 'result'에 경고를 받는다는 것을 알아 차렸다.이 경우 hello는 다음과 같다. 경고 한 –