AJAX 클래스 코드
2206 단어 AJAX
var ajax = new AjaxObj(url);
ajax.addListener(200, function(r){
alert(r);
});
ajax.send();
도 연속 으로 호출 할 수 있 습 니 다.
var ajax = new AjaxObj(url).addListener(200, function(r){
alert(r);
}).send();
또한 사용자 정의 POST 또는 GET 방식 요청 과 서로 다른 HTTP 상태 코드 를 감시 하고 코드 를 보고 다 듬 습 니 다.)전체 코드:
AjaxObj = function(url, method, content){
this.r = null;
this.url = url;
this.method = method;
this.content = content;
this.header = {};
this.header["Connection"] = "close";
this.header["Content-type"] = "application/x-www-form-urlencoded";
var self = this;
if(window.XMLHttpRequest){
this.r = new XMLHttpRequest();
}else if(window.ActiveXObject){
try {
this.r = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try{
this.r = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
}
}
}
this.addListener = function(http_status, func){
if(!this.L)
this.L=[];
this.L[http_status] = func;
return this;
};
this.setHeader = function(name, value){
this.header[name] = value;
this.r.setRequestHeader(name, value);
return this;
};
this.send = function(){
if(this.method != "post" && this.method != "get")
this.method = "get";
this.r.open(this.method, this.url, true);
for(var h in this.header) {
this.r.setRequestHeader(h, this.header[h]);
}
this.r.send(this.content);
};
if(this.r) this.r.onreadystatechange = function(){
if(self.r.readyState == 4 && self.L[self.r.status] != null)
self.L[self.r.status](self.r.responseText);
};
};
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
AJAX의 도메인 간 액세스 - 두 가지 효과적인 해결 방법 소개새로운 W3C 정책은 HTTP 크로스 도메인 접근을 실현했고 제가 오랫동안 이 문제를 해결한 덕분입니다. servlet에서 되돌아오는 머리 정보에 Access-Control-Allow-Origin을 추가하면 됩니다....
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.