Lösen Sie das Problem, dass der domänenübergreifende Ajax-Zugriff keine Berechtigungen meldet. Freunde in Not können darauf verweisen. smart.asp
Kopieren Sie den Codecode wie folgt:
<script language=jscript runat=server>
/*
Aufrufende Methode in VBS
dimme meinhttp
set myhttp = SmartHttp(url,method,data); //Alle drei Parameter sind optional
Eigentum:
URL: String, angeforderte URL-Adresse
method: String, angeforderte Methode
data: String, angeforderte Daten
Zeichensatz: Zeichenfolge, die Codierung der von der angeforderten URL zurückgegebenen Daten
Status: Int, der von der Anfrage zurückgegebene Statuscode
readyState: Int, aktueller Kommunikationsstatus mit HTTP-Anfrage, 1, 2, 3, 4
Datensatz: Objekt, die angeforderten Daten. Wenn dieser Teil der Daten hinzugefügt wird, wird er an das Datenattribut angehängt.
Datensatzeigenschaften:
Zeichensatz: String, Kodierung der gesendeten Daten
Datensatzmethode:
append(key,value,noencode): Daten hinzufügen
Remove(key): Entferne ein Datenelement
isexists(key): Bestimmen Sie, ob ein Datenelement vorhanden ist
clear: Alle Datenelemente löschen
Verfahren:
header(headstr): Legen Sie den Anforderungsheader fest und trennen Sie die Elemente und Werte durch:
timeout(t1,t2,t3,t4): Legen Sie die Timeout-Zeit fest
send(): Anfrage senden
getbinary: Vom Server zurückgegebene Binärdaten abrufen
gettext(charset): Ruft den Text der angegebenen Kodierung ab
getjson(charset): Ruft die JSON-Daten der angegebenen Kodierung ab
getheader(key): Ruft den vom Server zurückgegebenen Antwortheader ab
getxml(charset): XML-Daten der angegebenen Kodierung abrufen
*/
Funktion SmartHttp(url,method,data){
return new _SmartHttp(url,method,data);
}
Funktion _SmartHttp(url,method,data){
if(typeof method==undefiniert) method=GET;
if(typeof data==undefiniert) data=;
method = method.toUpperCase();
method = method!=POST ? GET : POST;
this.timeout=[10000,10000,10000,10000];
this.method = Methode;
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={
Zeichensatz:gb2312,
Daten:[],
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;
},
klar: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;
};
_SmartHttp.prototype.header=function(headstr){
if(headstr.indexOf(:)>=0) this.headers.push(headstr);
gib dies zurück;
};
_SmartHttp.prototype.timeout=function(){
if(arguments.length>4){return this;}
for(var i =0;i<arguments.length;i++){
if(!isNaN(arguments[i])){
this.timeout[i] = parseInt(arguments[i]);
}
}
gib dies zurück;
};
_SmartHttp.prototype.send=function(){
this.init();
var _http = this.getobj();
if(_http==null){dieses zurückgeben;}
versuchen{
_http.setTimeouts(this.timeout[0], this.timeout[1], this.timeout[2], this.timeout[3]);
}catch(ex){}
_http.open(this.method,this.url,false);
if(this.headers.length>0){
for(var i=0;i<this.headers.length;i++){
var Sindex = this.headers[i].indexOf(:);
var key = this.headers[i].substr(0,Sindex);
var value = this.headers[i].substr(Sindex+1);
_http.setRequestHeader(key,value);
}
}
_http.send(this.data);
this.readyState = _http.readyState;
if(_http.readyState==4){
this.status = parseInt(_http.status);
this.http = _http;
this.content = _http.responseBody;
}
gib dies zurück;
}
_SmartHttp.prototype.getbinary=function(){
return this.content;
};
_SmartHttp.prototype.gettext=function(charset){
versuchen{
return this.b2s(this.content,charset ? charset : this.charset);
}catch(ex){
this.msg = ex.description;
zurückkehren ;
}
};
_SmartHttp.prototype.getjson=function(charset){
versuchen{
var _json=null;
eval(_json=( + this.gettext(charset) + ););
return _json;
}catch(ex){
this.msg = ex.description;
null zurückgeben;
}
};
_SmartHttp.prototype.getheader=function(key){
if(key){
if(key.toUpperCase()==SET-COOKIE){
key = key.replace(-,/-);
var headers = this.http.getAllResponseHeaders();
var regexp = new RegExp(/n + key + /:(.+?)/r,ig);
var reststr = ;
while((res = regexp.exec(headers))!=null){
var val = res[1].trim();
resstr = resstr + val.substr(0,val.indexOf(;)) + ;
}
if(ressstr!=){
resstr = resstr.substr(0,resstr.lastIndexOf(;));
}
return reststr;
}anders{
return this.http.getResponseHeader(key);
}
}else{return this.http.getAllResponseHeaders();}
};
_SmartHttp.prototype.getxml=function(charset){
versuchen{
var _dom = new ActiveXObject(MSXML2.DOMDocument);
_dom.loadXML(this.gettext(charset));
return _dom;
}catch(ex){
this.msg = ex.description;
null zurückgeben;
}
};
_SmartHttp.prototype.getobj = function (){
var b=null;
var httplist = [MSXML2.serverXMLHttp.3.0,MSXML2.serverXMLHttp,MSXML2.XMLHttp.3.0,MSXML2.XMLHttp,Microsoft.XMLHttp];
for(var i = 0;i<=httplist.length -1;i++){
versuchen{
b= neues ActiveXObject(httplist[i]);
(Funktion(o){
_SmartHttp.prototype.getobj = function(){return new ActiveXObject(o)};
})(httplist[i]);
Rückkehr b;
}catch(ex){
eval(this.msg = ex.description;);
}
}
Rückkehr b;
};
_SmartHttp.prototype.getrnd = function (){return Math.random().toString().substr(2);};
_SmartHttp.prototype.b2s = function(bytSource, Cset){ //ef bb bf,c0 fd
var Objstream,c1,c2,c3;
var byts;
Objstream =Server.CreateObject(ADODB.Stream);
Objstream.Type = 1;
Objstream.Mode = 3;
Objstream.Open();
Objstream.Write(bytSource);
Objstream.Position = 0;
Objstream.Type = 2;
Objstream.CharSet = Cset;
byts = Objstream.ReadText();
Objstream.Close();
Objstream = null;
Bytes zurückgeben;
};
_SmartHttp.prototype.urlencode=function(str){ return encodeURIComponent(str);};
_SmartHttp.prototype.urldecode=function(str){ return decodeURIComponent(str);};
String.prototype.trim = function(){return this.replace(/(^(/s+)|(/s+)$)/igm,);};
</script>
Code verwenden:
Kopieren Sie den Codecode wie folgt:
<!--#include file=smart.asp-->
<%
Response.charset=utf-8
URL, Methode, Daten, Zeichensatz dimmen
url =Request.Form(targeturl)
Methode =Request.Form(Methode)
data =Request.Form(data)
charset = Request.Form(charset)
Wenn Zeichensatz =, dann Zeichensatz = GB2312
Antwort.Write SmartHttp(url,method,data).send().gettext(charset)
setze myhttp = nichts
%>