国产探花免费观看_亚洲丰满少妇自慰呻吟_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 文件上傳控件

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桐乡市| 峨眉山市| 清苑县| 荣成市| 渭南市| 平舆县| 乌什县| 安福县| 九寨沟县| 松潘县| 西安市| 徐水县| 花莲市| 尼木县| 德江县| 八宿县| 南充市| 南陵县| 右玉县| 井研县| 伊宁县| 元氏县| 沾化县| 浪卡子县| 临猗县| 榆中县| 祁连县| 贺兰县| 达拉特旗| 舟曲县| 晋城| 高台县| 普安县| 黄冈市| 云和县| 广平县| 定州市| 台南县| 莫力| 广汉市| 蒙山县|