/*******************************/
//operType : string , 标注的操作方式,"addMarker","editMarker","removeMarker"
//level : string , 级别
//name : string , 名称
//ico : string ,图标链接地址
//location : LTPoint,标注的地理位置
//successCallBack : function, 数据提交成功后的回调函数
//falseCallBack : function,数据提交失败后的回调函数
//var successCallBack1;
//var falseCallBack1;
//var xhr2;
//编写人:LFP
//////////////////////add by lfp 2008.8.15/////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var successCallBack1;
var falseCallBack1;
var xhr2;
function Ajax2(operType,level,name,ico,location,url,successCallBack,falseCallBack)
{
this.operType = operType;
this.level = level;
this.name = name;
this.ico = ico;
this.location = location
this.url = url;
successCallBack1 = successCallBack;
falseCallBack1 = falseCallBack;
xhr2 = LTAjax.createHttpRequest();
}
//提交标注数据到服务器
Ajax2.prototype.postMarkerData = function ()
{
var xmlData = "<Marker>";
xmlData += "<Level>" + this.level + "</Level>";
xmlData += "<Name>" + this.name + "</Name>";
xmlData += "<Icon>" + this.ico.replace("http://" + window.location.host,"") + "</Icon>";
xmlData += "<Latitude>" + this.location.getLatitude() + "</Latitude>";
xmlData += "<Longitude>" + this.location.getLongitude() + "</Longitude>";
xmlData += "</Marker>";
//xmlData = xmlData.replace(/</gi,"<").replace(/>/gi,">");
var pars = "oper=" + this.operType + "&xml=" + xmlData;
xhr2.open("POST",this.url,false);
xhr2.setRequestHeader("Content-Length",xmlData.length);
xhr2.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
xhr2.onreadystatechange = this.xhr2CallBack;
xhr2.send(pars);
}
//提交标注数据后的回调函数
Ajax2.prototype.xhr2CallBack = function (obj)
{
if (xhr2.readyState==4 || xhr2.readyState=="complete")
{
if(xhr2.status == 200 || xhr2.status == 304)
{
var str=xhr2.responseText;
var length1=str.length-1;
var sss=str.substring(length1,str.length);
if(xhr2.responseText.substring(length1,str.length) == "1") //需要取分号后面的值
{
successCallBack1();
//this = null;
}
else
{
falseCallBack1();
}
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////Ajax3/ add by LFP 2008.8.14 Begin/////////////////////////////////////
//Ajax3类功能:主要完成以xml作为参数传入的ajax请求处理
var successCallBack2;
var falseCallBack2;
var xhr3;
function Ajax3(operType,xmlData,url,successCallBack,falseCallBack)
{
this.operType=operType;
this.xmlData=xmlData;
this.url = url;
successCallBack2 = successCallBack;
falseCallBack2 = falseCallBack;
xhr3 = LTAjax.createHttpRequest();
}
//提交标注数据到服务器
Ajax3.prototype.postMarkerData= function ()
{
//xmlData = xmlData.replace(/</gi,"<").replace(/>/gi,">");
var pars = "oper=" + this.operType + "&xml=" +this.xmlData;
alert(pars);
xhr3.open("POST",this.url,false);
xhr3.setRequestHeader("Content-Length",this.xmlData.length);
xhr3.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
xhr3.onreadystatechange = this.xhr2CallBack;
xhr3.send(pars);
}
//提交标注数据后的回调函数
Ajax3.prototype.xhr2CallBack = function (obj)
{
if (xhr3.readyState==4 || xhr3.readyState=="complete")
{
if(xhr3.status == 200 || xhr3.status == 304)
{var str=xhr3.responseText;
var length1=str.length-1;
var sss=str.substring(length1,str.length);
alert(str);
alert(sss);
if(xhr3.responseText.substring(length1,str.length) == "1") //需要取分号后面的值
{
successCallBack2("xhr2CallBack3");
//this = null;
}
else
{
falseCallBack2();
}
}
}
}
///////////////Ajax3/ add by LFP 2008.8.14 End/////////////////////////////////////
// Ajax 封装 2007-3-13
function createXMLHttpRequest() {
try {
if (window.XMLHTTPRequest) {
return new XMLHttpRequest();
}
else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
catch (e) {alert("XMLHttpRequest对象无法创建!请检查IE安全设置!");}
}
function messageDiv(t)
{
var v = document.createElement("<div>");
v.innerHTML = "<table style=\"width:300px;\" id=message>" +
"<tr style=\"font-size:12px;background-color:#EEEEff;color:#227933;height:20px\">" +
"<td style=\"padding:2px;border-top:1px solid #E1E1E1;border-left:1px solid #E1E1E1;border-bottom:1px solid #818181;border-right:1px solid #A1A1A1\">" +
"<nobr><img src=refresh.gif align=absmiddle& gt; " + t + ",<span id=Span1>连接未初始化
</span></nobr>& lt;/td></tr></table>";var l = document.getElementsByName("message").length;
v.style.cssText = "position:absolute;bottom:" + (l*24) + "px;left:0px;display:none";
document.body.appendChild(v);
this.clear = function () {
document.body.removeChild(v);
var msg = document.getElementsByName("message");
for (var i=0;i<msg.length;i++){
msg[i].parentNode.style.cssText = "position:absolute;bottom:" + (i*24) + "px;left:0px";
}
}
this.showmsg = function (s) {
v.style.display = "";
//v.all.Span1.innerHTML = s;
}
}
function Ajax() {
var x = new createXMLHttpRequest();
this.Request = function (url,cmd,async,method,postString,title) {
if (method=="post") method = "post"; else method = "get";
if (async==true) async = true; else async = false;
if (typeof(postString)!="string") postString="";
if (typeof(title)!="string") title="正在获取数据"; else title="正在获取" + title;
var msgbox = new messageDiv(title);
x.onreadystatechange = function ()
{
if (async) switch (x.readystate) {
case 1:
msgbox.showmsg("正在初始化连接
");return;
case 2:
msgbox.showmsg("正在发送数据
");return;
case 3:
msgbox.showmsg("正在接收数据
");return;
case 4:
msgbox.showmsg("数据接收完成
");if (x.status == 200) {
cmd(x.responseText);
msgbox.clear();
}
else {
msgbox.showmsg("请求失败," + x.statustext + "(" + x.status + ")");
setTimeout(msgbox.clear,3000);
}
return;
}
}
x.open (method,url,async);
if (method=="post") {msgbox.showmsg("正在接收数据
");x.setRequestHeader("Content-Length",postString.length);x.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded"); x.send(postString);} else x.send();if (!async) {
msgbox.showmsg("数据接收完成
");cmd(x.responseText);
msgbox.clear();
}
}
}
浙公网安备 33010602011771号