Copy Code code as follows:
/**//*
Asynchronous Request Class
Author: I am not intentional
Date Created: 2009.2
--------------------------------------------------------------------------------------------------------------- ------------------
To modify a record:
2009.4.27--Add URL detection function, if it is "http://xxxx.xxx.xx.xx/..." Such a format, using the "/geturl.aspx" provided by the system to obtain
To resolve cross-domain problems.
The main parameters of the geturl.aspx are two: 1, the URL value is the target URL (can be with parameters in the URL)--must; 2, method value is used by the agent (optional)
If the method is null, the proxy is by default, and if the form parameter is empty (that is, request.content-length=0), it is automatically set to get methods;
(Note: Geturl.aspx was redesigned in 2009.4.27 and a cookie agent was added on the basis of the original completion agent)
*/
function Isouterurl (str_url) {
var Strregex = "((https|http)://) ([\\w-]+\\.) +[\\w-]+. ([^a-z]) (/[\\w-./?%&=]*)? | ((https|http)://) [A-za-z0-9\\-\\.] [\\w-]+. ([^a-z]) (/[\\w-./?%&=]*)? ";
var re=new RegExp (Strregex);
if (Re.test (Str_url)) {
return (true);
}else{
return (false);
}
}
var leesajaxrequest=
{
List:[],
M_leesajaxhttprequest:null,
Isworking:false,
Geturl:function (Method,url,params,successfun,failurefun,headers)
{
if (url.length<1)
Return
if (this.m_leesajaxhttprequest==null)
{
if (typeof XMLHttpRequest!= ' undefined ')
{
This.m_leesajaxhttprequest = new XMLHttpRequest ();
}
else if (typeof activexobject!= ' undefined ')
{
This.m_leesajaxhttprequest = new ActiveXObject (' microsoft.xmlhttp ');
}
}
if (this.m_leesajaxhttprequest)
{
if (this.isworking)
{
This.list[this.list.length]={method:method,url:url,params:params,successfun:successfun,failurefun:failurefun, Headers:headers};
}
Else
{
This.isworking=true;
if (Isouterurl (URL))
This.m_LeesAjaxHttpRequest.open (method, "/geturl.aspx?url=" +escape (URL) + "&method=" +method, true);//true to asynchronous
Else
This.m_LeesAjaxHttpRequest.open (method, URL, true);//true is asynchronous
var _this=this;
This.m_leesajaxhttprequest.onreadystatechange=function ()
{
if (4==_this.m_leesajaxhttprequest.readystate)
{
if (200==_this.m_leesajaxhttprequest.status)
{
if (Successfun)
{
try{
Successfun (_this.m_leesajaxhttprequest);
}
catch (ex)
{}
}
}
Else
{
if (Failurefun)
{
try{
Failurefun (_this.m_leesajaxhttprequest);
}
catch (ex)
{}
}
}
_this.isworking=false;
if (_this.list.length>0)
{
var o=_this.list[0];
_this.list.splice (0,1);
_this.geturl (o.method,o.url,o.params,o.successfun,o.failurefun,o.headers);
}
}
};
var vpara= "";
if (typeof params== "string")
{
Vpara=escape (params);
}
else if (params)
{
Try
{
for (var e in params)
{
if (vpara.length<1)
Vpara=e+ "=" +escape (Params[e]);
Else
vpara+= "&" +e+ "=" +escape (params[e);
}
}
catch (ex)
{}
}
if (headers)
{
Try
{
for (Var h in headers)
{
This.m_LeesAjaxHttpRequest.setRequestHeader (H.replace ("_", "-"), Headers[h]);
}
}
catch (ex)
{
}
}
This.m_LeesAjaxHttpRequest.send (Vpara);
}
}
},
Post:function (o)
{
var vmethod=o.method| | " Post ";
var vurl=o.url| | Null
var vparams=o.params| | "";
var vsuccess=o.success| | Null
var vfailure=o.failure| | Null
var vheaders=o.headers| | Null
if (vurl==null| | VURL.LENGTH<1)
{
Alert ("Malformed asynchronous request Format");
Return
}
This.geturl (vmethod,vurl,vparams,vsuccess,vfailure,vheaders);
},
Get:function (o)
{
var vmethod=o.method| | " Get ";
var vurl=o.url| | Null
var vparams=o.params| | "";
var vsuccess=o.success| | Null
var vfailure=o.failure| | Null
var vheaders=o.headers| | Null
if (vurl==null| | VURL.LENGTH<1)
{
Alert ("Malformed asynchronous request Format");
Return
}
This.geturl (vmethod,vurl,vparams,vsuccess,vfailure,vheaders);
}
}
/**//* Asynchronous Request Class end*/
Use examples:
Copy Code code as follows:
1.//Dynamic load JS file
if (VJs && vjs.length>3)
{
if (!_this.loadedjs.isinarray (VJS))
{
_this.loadedjs[_this.loadedjs.length]=vjs;
Leesajaxrequest.get ({
Url:vjs,
Success:function (OJS) {
var jsobj=document.createelement ("script");
Jsobj.text=ojs.responsetext;
Document.documentElement.appendChild (Jsobj);
},//end success
Headers:{content_type: "Application/x-javascript"}
});//end get
}//end if (!_this.loadedjs.isinarray (VJS))
}//end if (VJs && vjs.length>3)
2.//Add to tool tip vertical bar
Leesajaxrequest.post ({url: "/gettooltip.aspx",
Params:{tooltip:title},
Headers:{content_type: "Application/x-www-form-urlencoded;charset=utf-8"},//if you use the Post method, you must pass in this parameter, CharSet can be other
Success:function (o) {
var robj=eval ("(" +o.responsetext+ ")");
var tobj=new leesbasewindow (robj["width"]+2,robj["height"]+1, "", "", "", "", "", 1, "" "");
Tobj.showwindow (Vtoolbarslider.window);
tobj.contentwindow.style.backgroundimage= "url (" +robj["image"]+ ")";
Tobj.contentwindow.style.marginleft= "1px";
tobj.contentwindow.style.backgroundrepeat= "No-repeat";
tobj.contentwindow.style.backgroundposition= "0 0";
Tobj.contentwindow.onmouseover=function () {
this.style.backgroundposition= "0-" +robj.height;
_this.setshowwindow (obj);
}
Tobj.contentwindow.onmouseout=function () {
this.style.backgroundposition= "0 0";
}
},
Failure:function () {
Alert ("Error generating tooltip");
}
});