• 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是很多坐标串可能就会失败)。

    多看一行书,就少写一行代码,记录点滴,用心生活。
  • 相关阅读:
    docker--docker介绍
    docker--虚拟化
    高级运维工程师的打怪升级之路
    mysql常用函数
    CentOS 7 下使用 Firewall
    51nod 1094 和为k的连续区间(map+前缀和)
    51nod 1092 回文字符串(dp)
    51nod 1062 序列中最大的数(打表预处理)
    51nod 1284 2 3 5 7的倍数(容斥原理+反面思考)
    51nod 1347 旋转字符串(思维好题)
  • 原文地址:https://www.cnblogs.com/aegisada/p/4242519.html
Copyright © 2020-2023  润新知