冷面阎罗
低调做人&&高调做事
随笔 - 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
冷面阎罗
阅读(1246)
评论(1)
编辑
收藏
评论
#
re: 过完年了,回单位上班了,总结一下ajax加载文档的生命周期
回复
更多评论
过完年了,还是要加班,真不爽
2007-03-02 22:51 |
Druze.libo
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理
Powered by:
BlogJava
Copyright © 冷面阎罗
导航
管理
文章档案
2007年5月 (1)
2007年4月 (1)
2007年3月 (1)
最新评论
1. re: 动态给select添加选项的常用方法
garb
--自行车
2. re: 动态给select添加选项的常用方法
第三方菲菲
--自行车
3. re: 对前几天作的java万年历,再弄修改,加上农历
建议用冬月、腊月而不是十一月、十二月等
---
4. re: java代码中顺序问题,养成良好代码书写习惯
问额外
--对方是否
5. re: HTTP请求发送XML数据
ios中的发送裸数据xml怎么发送
--夜莺