zoukankan      html  css  js  c++  java
  • ajax 原生态和jquery封装区别

    一、原生态

    var xmlHttp = false;
    try{
    	if( xmlHttp && xmlHttp.readyState != 0 ){
    	    xmlHttp.abort();
             }	
    	if (!xmlHttp){
    	    xmlHttp = getXMLHTTPObj();     			
    	}			
    	if(xmlHttp){  
    	    var url = "pages/overlapanalysis_PostResult.jsp?dkName="+dkName+"&annlysisBusinessType="+annlysisBusinessType
    				           +"&coordString="+coordString+"&mapID="+mapID+"&phyLayerID="+phyLayerID+"&phyLayerName="+phyLayerName
    						   +"&fldNames="+fldNames+"&whereSql="+whereSql;
    	    xmlHttp.open("POST",encodeURI(encodeURI(url)) , true);   
    	    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    	    xmlHttp.setRequestHeader("Content-Type","text/xml;charset=GBK");
    	   //设置回调函数
    	   xmlHttp.onreadystatechange = function () {
    	      try{
    		if (xmlHttp.readyState == 1){
    		    window.status = "叠加分析中......";  		     		
    		}else if (xmlHttp.readyState == 2){
    		    window.status = "叠加分析完毕";       	  	
    		}else if (xmlHttp.readyState == 3){
    		    window.status = "叠加分析完毕.";       		
    		}else if (xmlHttp.readyState == 4){
    		    window.status = "叠加分析完毕.";
    		    var retStr = xmlHttp.responseText;
    		    document.getElementById("data_txt").value = retStr;
    		}
    		}catch (e){
    		    alert("数据加载失败!:" + e);
    		}
    	}
    	xmlHttp.send(null);         
    	}else{
    	    alert("XMLHTTP对象创建失败");
    	 }
    	}catch (e){
    	    alert("数据加载失败!:" + e);
    }
    
    
    
     //创建XMLHTTP对象
    function getXMLHTTPObj(){
    		  var obj = null;
    		  try{
    			  obj = new ActiveXObject("Msxml2.XMLHTTP");
    		  }catch(e){
    		try{
    			obj = new ActiveXObject("Microsoft.XMLHTTP");
    		}catch(sc){
    			obj = null;
    			alert('创建XMLHTTP对象失败!');
    		}
    	  }
    	 if( !obj && typeof XMLHttpRequest != "undefined" ){  //not Microsoft Integer Explorer
    		 obj = new XMLHttpRequest();
    	 }
    	 return obj;
    }
    
    $.ajax({      
               url:"pages/overlapanalysis_PostResult.jsp",      
               type:"post",      
               data:"dkName="+dkName+"&annlysisBusinessType="+annlysisBusinessType
    				           +"&coordString="+coordStr+"&mapID="+mapID+"&phyLayerID="+phyLayerID+"&phyLayerName="+phyLayerName
    						   +"&fldNames="+fldNames+"&whereSql="+whereSql,      
               async : true, //默认为true 异步    
    		   dataType:"html",		
               error:function(){      
                   alert("叠加分析失败");      
               },      
               success:function(data){  
                   setAttributeValuestt(layerType,coordStr,data);  
               }   
        });  
    

     当使用的参数较多且有的参数过长时建议使用jquery的,使用原生态的可以会截掉部分传递的参数(如coordStr是很多坐标串可能就会失败)。

    多看一行书,就少写一行代码,记录点滴,用心生活。
  • 相关阅读:
    实现div 垂直居中
    CSS 轮廓---outline属性
    CSS 伪类 (Pseudo-classes)
    HTML默认样式和浏览器默认样式
    VHDL之concurrent之block
    VHDL之concurrent之generate
    VHDL之concurrent之when
    VHDL之concurrent之operators
    QS之force(2)
    QS之force(1)
  • 原文地址:https://www.cnblogs.com/aegisada/p/4242519.html
Copyright © 2011-2022 走看看