ajax学习


 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);
                 }
             }
     }





你可能感兴趣的:(Ajax,exception,function,null,url,XMLhttpREquest)