📄 ajax.js
字号:
//sarissa.js needed
var ajax = new Object();
ajax.READY_STATE_COMPLETE = 4;
ajax.loader = function(url, method, onload, onerror, data, contentType){
this.req = null;
this.onload = onload;
this.onerror = (onerror) ? onerror : this.defaultError;
this.send(url, method, data, contentType);
}
ajax.loader.prototype = {
send : function(url, method, data, contentType){
if(!method){
method = 'GET';
}
if(!contentType && method == 'POST'){
contentType = 'application/x-www-form-urlencoded';
}
this.req = new XMLHttpRequest();
if(!this.req){
this.onerror.call(this);
}
try{
var loader = this;
this.req.onreadystatechange = function(){
loader.onReadyState.call(loader);
}
this.req.open(method, url, true);
if(contentType){
this.req.setRequestHeader('Content-Type', contentType);
}
this.req.send(data);
}catch(e){
this.onerror.call(this);
}
},
onReadyState : function(){
var req = this.req;
if(req.readyState == ajax.READY_STATE_COMPLETE){
var httpStatus = req.status;
if(httpStatus == 200 || httpStatus == 0){
this.onload.call(this);
}else{
this.onerror.call(this);
}
}
},
defaultError : function(){
alert('请求失败,请重试。');
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -