ajax学习

来源:互联网 发布:琢本网络 编辑:程序博客网 时间:2024/06/05 17:21


 function saveGooglePOI(){     var destination=encodeURI(document.getElementById("destination").value);     var lonlat1=document.getElementById("latlon").value;     var lonlat=lonlat1.split(",");     var lng=lonlat[0];     var lat=lonlat[1];     if(lonlat.length<2){         alert("请输入信息");         return;        }     var tercode=document.getElementById("telephone").value;     var url="<%=request.getContextPath()%>/SavePOIAction?poiLon="+lng+"&poiLat="+lat+"&termcode="+tercode+"&poiName="+destination;     var xmlHttp=null;     if(window.ActiveXObject){             xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");             }      else if(window.XMLHttpRequest){             xmlHttp = new XMLHttpRequest();              }   try {             xmlHttp.open("POST",url, true);             xmlHttp.onreadystatechange = function(){ showBackResult(xmlHttp);}             xmlHttp.send(null);         }         catch(exception)         {             alert("xmlHttp Fail");         } }   function showBackResult(xmlHttp){      if(xmlHttp.readyState == 4)             {                         if (xmlHttp.status == 200 || xmlHttp.status == 0)                 {                        var result = xmlHttp.responseText;                          alert(result);                 }             }     }