冷面阎罗

低调做人&&高调做事
随笔 - 208, 文章 - 3, 评论 - 593, 引用 - 0
数据加载中……

过完年了,回单位上班了,总结一下ajax加载文档的生命周期

过年放假差不多半个月,在家呆着好舒服,真是有点不想回来,回来又要面对新一年的工作,自己想想又要拼搏一年了。感觉自己肩上的责任比去年大多了。
到五一钱可能不用出差了,感慨一下:终于可以过正常人的生活了!
过年没给自己买什么,买了点关于软件的书,先研究ajax吧。

先总结一下自己假期学的:关于ajax加载文档的生命周期。
我们可以从这个程序中看出,不同浏览器对加载文档的输出不一样,但是最后的结果却是一样。
<html>
<head>
<script type='text/javascript'>
var req=null;
var console=null;

function sendRequest(url,params,HttpMethod){
if(!HttpMethod){
HttpMethod
="GET";
}

req
=initXMLHTTPRequest();
if(req){
req.onreadystatechange
=onReadyState;
req.open(HttpMethod,url,
true);
//req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
req.send(params);
}

}


function initXMLHTTPRequest(){
var xRequest=null;
if(window.XMLHttpRequest){
xRequest
=new XMLHttpRequest();
}
 else if(window.ActiveXObject){
xRequest 
= new ActiveXObject("Microsoft.XMLHTTP");
}

return xRequest;
}


function onReadyState(){
var ready=req.readyState;
var data=null;
if(ready==4){
data.responseText;
}
else{
data
="loading ["+ready+"]";
}

toconsole(data);
}


function toconsole(data){
if(console!=null){
var newline=document.createElement("div");
console.appendChild(newline);
var txt=document.createTextNode(data);
newline.appendChild(txt);
}

}


window.onload
=function(){
console
=document.getElementById('console');
sendRequest(
"data.txt");
}

</script>
</head>
<body id='console'></div>
</body>
</html>

posted on 2007-02-28 16:20 冷面阎罗 阅读(1233) 评论(1)  编辑  收藏

评论

# re: 过完年了,回单位上班了,总结一下ajax加载文档的生命周期  回复  更多评论   

过完年了,还是要加班,真不爽
2007-03-02 22:51 | Druze.libo

只有注册用户登录后才能发表评论。


网站导航: