首页上一页 1 下一页尾页 1 条记录 1/1页
PHP模块开发
发表在PHP图书答疑
2013-12-21
是否精华
是
否
版块置顶:
是
否
var net=new Object();
net.AjaxRequest=function(url,onload,onerror,method,params){
this.req=null;
this.onload=onload;
this.onerror=(onerror)?onerror:this.defaultError;
this.loadDate(url,method,params);
}
net.AjaxRequest.prototype.loadDate=function(url,method,params){
if(!method){
method="GET";
}
if(window.XMLHttpRequest){
this.req=new XMLHttpRequest();
} else if(window.ActiveXObject){
this.req=new ActiveXObject("Microsoft.XMLHTTP");
}
if(this.req){
try{
var loader=this;[font color=#FF0000]/*this指的是net.AjaxRequest.XMLHttpRequest吗? 还是net.
XMLHttpReques*/[/font]
this.req.onreadystatechange=function(){
net.AjaxRequest.onReadyState.call(loader);
}
this.req.open(method,url,true);
if(method=="POST"){
this.req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
this.req.send(params);
} catch(err){
this.onerror.call(this);
}
}
}
net.AjaxRequest.onReadyState=function(){
var req=this.req;
var ready=req.readyState;
if(ready==4){
if(req.status==200){
this.onload.call(this);
} else {
this.onerror.call(this);
}
}
}
net.AjaxRequest.prototype.defaultError=function(){
alert("error fetching data!"
+"\n\nreadyState:"+this.req.readyState
+"\nstatus:"+this.req.status
+"\nheaders:"+this.req.getAllResponseHeaders());
}
[font color=#00FF00]net.AjaxRequest是net对象的AjaxRequest方法,但是上面代码中net.AjaxRequest.prototype,意思是对象中的方法也可以用prototype来添加方法和属性吗?w3c网站上只给出了在对象中使用prototype属性啊。[/font]
net.AjaxRequest=function(url,onload,onerror,method,params){
this.req=null;
this.onload=onload;
this.onerror=(onerror)?onerror:this.defaultError;
this.loadDate(url,method,params);
}
net.AjaxRequest.prototype.loadDate=function(url,method,params){
if(!method){
method="GET";
}
if(window.XMLHttpRequest){
this.req=new XMLHttpRequest();
} else if(window.ActiveXObject){
this.req=new ActiveXObject("Microsoft.XMLHTTP");
}
if(this.req){
try{
var loader=this;[font color=#FF0000]/*this指的是net.AjaxRequest.XMLHttpRequest吗? 还是net.
XMLHttpReques*/[/font]
this.req.onreadystatechange=function(){
net.AjaxRequest.onReadyState.call(loader);
}
this.req.open(method,url,true);
if(method=="POST"){
this.req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
this.req.send(params);
} catch(err){
this.onerror.call(this);
}
}
}
net.AjaxRequest.onReadyState=function(){
var req=this.req;
var ready=req.readyState;
if(ready==4){
if(req.status==200){
this.onload.call(this);
} else {
this.onerror.call(this);
}
}
}
net.AjaxRequest.prototype.defaultError=function(){
alert("error fetching data!"
+"\n\nreadyState:"+this.req.readyState
+"\nstatus:"+this.req.status
+"\nheaders:"+this.req.getAllResponseHeaders());
}
[font color=#00FF00]net.AjaxRequest是net对象的AjaxRequest方法,但是上面代码中net.AjaxRequest.prototype,意思是对象中的方法也可以用prototype来添加方法和属性吗?w3c网站上只给出了在对象中使用prototype属性啊。[/font]