Ajax跨域代理访问网络信息的实现代码
发布时间:2023-08-02 10:27:52 所属栏目:Asp教程 来源:
导读:smart.asp
复制代码 代码如下:
<script language="jscript" runat="server">
/*
在VBS里面的调用方法
dim myhttp
set myhttp = SmartHttp(url,method,data); //三个参数均可选
属性:
url:String,请求的
复制代码 代码如下:
<script language="jscript" runat="server">
/*
在VBS里面的调用方法
dim myhttp
set myhttp = SmartHttp(url,method,data); //三个参数均可选
属性:
url:String,请求的
smart.asp 复制代码 代码如下: <script language="jscript" runat="server"> /* 在VBS里面的调用方法 dim myhttp set myhttp = SmartHttp(url,method,data); //三个参数均可选 属性: url:String,请求的URL地址 method:String,请求的方法 data:String,请求的数据 charset:String,请求的URL返回数据的编码 status:Int,请求返回的状态码 readyState:Int,同HTTP请求的当前通讯状态,1、2、3、4 dataset:Object,请求的数据,如果增加了,会将这部分数据附加到data属性 dataset属性: charset:String,发送数据的编码 dataset方法: append(key,value,noencode):添加数据 remove(key):移除某个数据项 isexists(key):判断某个数据项是不是存在 clear:清除所有数据项 方法: header(headstr):设置请求头,项和值之间用:分开 timeout(t1,t2,t3,t4):设置超时时间 send():发送请求 getbinary:获取服务器返回的二进制数据 gettext(charset):获取指定编码的文本 getjson(charset):获取指定编码的json数据 getheader(key):获取服务器返回的响应头 getxml(charset):获取指定编码的xml数据 */ function SmartHttp(url,method,data){ return new _SmartHttp(url,method,data); } function _SmartHttp(url,method,data){ if(typeof method=="undefined") method="GET"; if(typeof data=="undefined") data=""; method = method.toUpperCase(); method = method!="POST" ? "GET" : "POST"; this.timeout=[10000,10000,10000,10000]; this.method = method; this.url=url; this.data=data; this.charset="gb2312"; this.http=null; this.headers=[]; this.status=0; this.readyState=0; this.content=null; this.msg=""; this.dataset={ charset:"gb2312", data:[], append:function(key,value,noencode){ var fn=null; if(this.charset.toLowerCase()=="utf-8"){fn = encodeURIComponent;}else{fn = escape;} if(noencode==true){fn=function(_str){return _str;}} this.data.push({"key":fn(key),"value":fn(value)}); }, remove:function(key){ if(this.data.length<=0) return false; var _data=[]; for(var i=0;i<this.data.length;i++){ if(this.data[i].key!=key){ _data.push(this.data[i]); } } this.data = _data; }, isexists:function(key){ if(this.data.length<=0) return false; for(var i=0;i<this.data.length;i++){ if(this.data[i].key==key){ return true; } } return false; }, clear:function(){ this.dataset.data=[]; } }; } _SmartHttp.prototype.init=function(){ var datasetstr=""; if(this.dataset.data.length>0){ for(var i=0;i<this.dataset.data.length;i++){ datasetstr += this.dataset.data[i].key + "=" + this.dataset.data[i].value + "&"; } } if(datasetstr!="") datasetstr = datasetstr.substr(0,datasetstr.length-1); if(this.data==""){this.data = datasetstr;}else{if(datasetstr!="")this.data+= "&" + datasetstr;} if(this.data=="")this.data=null; //this.url += ((this.url.indexOf("?")<0) ? "?" : "&") + "jornd=" + this.getrnd(); if(this.method=="GET" && this.data!=null) this.url += "&" + this.data; if(this.method=="POST") this.headers.push("Content-Type:application/x-www-form-urlencoded"); if(!this.charset || this.charset=="") this.charset = "gb2312"; }; (编辑:汽车网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐