国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > AJAX > 正文

Ajax異步(請求)提交類 支持跨域

2024-09-01 08:29:25
字體:
來源:轉載
供稿:網友
代碼如下:
/**//*
異步請求類

作者:吾非無心
創建時間:2009.2
---------------------------------------------------------------------------------------------------------------------------------

修改記錄:

2009.4.27——添加 URL 檢測功能,如果是“http://xxxx.xxx.xx.xx/..”這樣的格式,使用系統提供的“/getUrl.aspx”進行獲取
以解決跨域問題。
getUrl.aspx 的主要參數有兩個:1、url 值為目標URL(URL中可以帶參數)——必須;2、method 值為代理使用的方法(可選)
如果method為空,默認采用POST方法進行代理;如果FORM參數為空(即request.content-length=0),則自動設置為GET方法;
(注:getUrl.aspx在2009.4.27重新進行了設計,在原完成代理的基礎上,新增了Cookie代理)
*/
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為異步
else
this.m_LeesAjaxHttpRequest.open(method, url, true);//true為異步
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]);
上一篇:ajax poller

下一篇:5款Ajax 文件上傳控件

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平度市| 阿荣旗| 平邑县| 南昌县| 大丰市| 屏东市| 山阳县| 永嘉县| 祥云县| 泾阳县| 福海县| 民和| 布尔津县| 承德市| 民丰县| 宁陕县| 邹城市| 彩票| 新和县| 句容市| 资兴市| 杭锦后旗| 锡林郭勒盟| 鄱阳县| 临夏市| 蛟河市| 和平县| 庆阳市| 屯留县| 满洲里市| 荔波县| 保山市| 凤凰县| 永吉县| 崇明县| 白水县| 桐乡市| 乌兰浩特市| 马山县| 新化县| 衡东县|