look to the master, follow the master, walk with the master, see through the master, become the master.
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} 1213function 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} 2223function 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。
Powered by: BlogJava Copyright © kukooBlog