我正在使用谷歌地圖API獲取位置。我已經使用了地址字段的變化下面的函數。它正在正常工作。在使用onsubmit屬性提交時,我使用同樣的形式提交了相同的函數來再次檢查函數。但提交時,我無法從這個Ajax獲得答案,因爲使用此返回返回真正的形式提交與p得到答案。javascript ajax上提交
請任何一個找到這個
function validatePlaceForm(){
var frm = document.frmOncampus;
var oncampusAddress = frm.oncampusAddress.value;
var xmlhttp;
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
//document.getElementById("my_div").innerHTML=''
var result =xmlhttp.responseText;
//alert(result);
var both =result.split("|");
frm.oncampusLatitude.value=both[0];
frm.oncampusLongtitude.value=both[1];
}
}
var url='latlog.php?address='+oncampusAddress;
xmlhttp.open("GET",url,true);
xmlhttp.send();
return true;
}
只有當地址有效時才返回true否則返回false。請包含您的html代碼以獲取更多詳細信息。 –
也許是時候查看[jQuery](http://jquery.com/)了? – Blender
我試過在jquery中也都有同樣的問題。 – swamy