一、原生态

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

05-11 15:24