Blog信息 |
blog名称: 日志总数:1304 评论数量:2242 留言数量:5 访问次数:7587795 建立时间:2006年5月29日 |

| |
[Prototype(Ajax)]利用ajax实现实施刷新 软件技术
lhwork 发表于 2006/10/17 10:01:53 |
很多应用都有实施刷新的需求,用
html
或
javascript
的刷新方式都是全局刷新,客户能够明显感觉到闪动。介绍种
ajax
实现在实施刷新技术。
使用
xmlhttp.htm
实时刷新,访问
http://127.0.0.1:7001/xmlhttp.jsp
页面,由
xmlhttp.jsp
页面写入随机数。
500)this.width=500'>
<
html
>
500)this.width=500'>
<
head
><
title
>
test
</
title
>
500)this.width=500'>
<
script language
=
"
javascript
"
>
500)this.width=500'>function detect()500)this.width=500'>500)this.width=500'>
500)this.width=500'>
{ 500)this.width=500'> xml
=
new
ActiveXObject(
"
Microsoft.XMLHTTP
"
); 500)this.width=500'> var post
=
"
"
; 500)this.width=500'> xml.open(
"
POST
"
,
"
http://127.0.0.1:7001/xmlhttp.jsp
"
,
false
);500)this.width=500'> xml.setrequestheader(
"
content-length
"
,post.length); 500)this.width=500'> xml.setrequestheader(
"
content-type
"
,
"
application/x-www-form-urlencoded
"
); 500)this.width=500'> xml.send(post); 500)this.width=500'> var res
=
xml.responseText; 500)this.width=500'> list.innerText
=
res; 500)this.width=500'>
//
设置自动刷新时间
500)this.width=500'>
setTimeout(
"
detect()
"
,
1000
); 500)this.width=500'>}
500)this.width=500'>
</
script
>
500)this.width=500'>
<
body onload
=
"
detect()
"
>
500)this.width=500'>test : 500)this.width=500'>
<
a id
=
"
list
"
></
a
>
500)this.width=500'>
</
body
>
500)this.width=500'>
</
html
>
500)this.width=500'>
xmlhttp.jsp
利用随机数测试
500)this.width=500'>
<%
@ page
import
=
"
java.util.Random
"
%>
500)this.width=500'>
<%
@ page language
=
"
java
"
contentType
=
"
text/html;charset=gb2312
"
%>
500)this.width=500'>
<%
500)this.width=500'> Random random
=
new
Random();500)this.width=500'> out.println(random.nextInt());500)this.width=500'>
%>
500)this.width=500'>
|
|
|