kukooBlog

look to the master, follow the master, walk with the master, see through the master, become the master.

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  213 随笔 :: 0 文章 :: 285 评论 :: 0 Trackbacks
首先让我们先知道一下什么是AJAX(注意这不是荷兰的甲级足球俱乐部阿甲克斯)。AJAX的全称是: Asynchronous JavaScript And XML。

JavaRSS.com是一个关于Java新闻的聚合站点,收录了几乎全部的关于Java的网站的新闻,比如TheServerside。这些新闻,除了标题之外,还有一些简单的说明,如果把这些说明一次性的显示在首页上,那么时间估计会相当长(因为首页显示了大约600条新闻)。JavaRSS.com在首页上就采用了AJAX技术,通过Lazy Loading来处理:即只有当用户把鼠标移到这个新闻标题上的时候,才会显示这个简单的说明。

JavaRSS.com在他自己的网站上公布了使用AJAX的细节。它的关键部分就是以下的代码:

 1function getDescription(channelId,itemId) {     
 2   var url = 'http://localhost:8080/getDescription.jsp?channelId=' + channelId + '&itemId=' + itemId;     
 3   if (window.XMLHttpRequest) {         
 4      req = new XMLHttpRequest();     
 5   } else if (window.ActiveXObject) {         
 6      req = new ActiveXObject("Microsoft.XMLHTTP");     
 7   }     
 8   req.onreadystatechange = processRequest;     
 9   req.open("GET", url, true);     
10   req.send(null); 
11
12
13function processRequest() {     
14   if (req.readyState == 4) {         
15      if (req.status == 200) {           
16         parseMessages();         
17      } else {           
18         alert ( "Not able to retrieve description" );         
19      }     
20   } 
21
22
23function parseMessages() {         
24   response = req.responseXML.documentElement;         
25   itemDescription = response.getElementsByTagName('description')[0].firstChild.data;         
26   alert ( itemDescription ); 
27}


TheServerside上面post了一条评论“AJAX In Action on JavaRSS”,有兴趣的可以看看。其实,Google Map, Gmail 都在使用AJAX。

posted on 2005-05-17 15:54 kukooBlog 阅读(486) 评论(0)  编辑  收藏 所属分类: Others

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


网站导航: