Position: All -> Site News -> Ôö¼ÓÁËAjax×îÐÂÆÀÂÛ×Ô¶¯Ìáʾ¹¦ÄÜ | 07-09-29 20:50:03
Font-Size:
Large | Middle | Small

ÓÖµ÷ÊÔÁË3¸öСʱ£¬ºÃÀÛ……²»¹ý»¹Ëãѧµ½¸ö²»´ó²»Ð¡µÄ¶«Î÷°Ñ£¬ÆðÂëÔÙ´ÎÁìÎòÁËajaxµÄÁ÷³Ì……

Õâ¸ö¹¦ÄÜÊÇÕâÑùµÄ£ºµ±ÄãÔÚä¯ÀÀ±¾Õ¾ÈκÎÒ»¸öÒ³ÃæÊ±£¬ÈôÁíÍâÒ»¸öÈËÔÚijƪÎÄÕÂÖз¢±íÁËÒ»ÌõÆÀÂÛ£¬ÔòÄãÕýÔÚ¿´µÄÍøÒ³ÉÏ·½»á×Ô¶¯µ¯³öÀ´Ò»¸ö¿ò£¬ÌáʾÄãÓÐÒ»ÌõÐÂÆÀÂÛ£¬ÏÂÃæÓиöÁ´½Ó£¬¿ÉÒÔµã½øÈ¥¾ßÌå²é¿´±¾ÌõÆÀÂÛ£¬Õû¸ö¹ý³Ì¶¼ÊÇÔÚÒ³Ãæ²»Ë¢ÐµÄÇé¿öϽøÐеÄŶ£¬ËùÒÔÍêÈ«²»Ó°ÏìÄãä¯ÀÀÎÄÕ£¬Ëù˵µÄЧ¹ûÈçÏ£º

°ÑJS´úÂë·¢À´¹²Ïí£¬PHP´úÂëÉæ¼°Êý¾Ý¿â°²È«¾Í²»·¢ÁË = =

JavaScript´úÂë
  1. var oXmlHttp = null;   
  2. var interval = 1000;   
  3. var lastCommentId = -1;   
  4. var divNotification = null;   
  5.   
  6. function showNotification (article_id,name,message) {   
  7.     /*if (!divNotification) {  
  8.         divNotification = document.createElement("div");  
  9.         divNotification.className = "notification";  
  10.         document.body.appendChild(divNotification);  
  11.     }*/  
  12.     divNotification = document.getElementById("divNotification");   
  13.     divNotification.innerHTML = "<strong>There is a new comment!(ÓÐÈË·¢±íÁËÒ»Ìõ×îÐÂÆÀÂÛ!)</strong><br /><br /><strong>" + name + " says(˵):" + message + "...</strong><br /><br /><strong><a class=\"tip\" href=\"view.php?id=" + article_id + "#cmtid" + lastCommentId + "\">view this comment(²é¿´ÕâÌõÆÀÂÛ)</a></strong>";   
  14.     divNotification.style.top = document.body.scrollTop + "px";   
  15.     divNotification.style.left = document.body.scrollLeft + "px";   
  16.     divNotification.style.display = "block";   
  17.     setTimeout(function () {divNotification.style.display = "none";},10000);   
  18. }   
  19.   
  20. function checkComment () {   
  21.     if (!oXmlHttp) {   
  22.         oXmlHttp = zXmlHttp.createRequest();   
  23.     } else if (oXmlHttp.readyState != 0 ) {   
  24.         oXmlHttp.abort();   
  25.     }   
  26.     oXmlHttp.open("GET","ajax_checkcomment.php",true);   
  27.     oXmlHttp.onreadystatechange = function () {   
  28.         if(oXmlHttp.readyState == 4) {   
  29.             if(oXmlHttp.status == 200) {   
  30.                 var arrInfo = oXmlHttp.responseText.split("||");   
  31.                 //lastCommentId = arrInfo[0];   
  32.                 if (arrInfo[0] != lastCommentId) {   
  33.                     if (lastCommentId != -1) {   
  34.                        showNotification(arrInfo[1],arrInfo[2],arrInfo[3]);   
  35.                     }   
  36.                     lastCommentId = arrInfo[0];   
  37.                 }   
  38.             setTimeout(checkComment,interval);   
  39.             }   
  40.         }   
  41.     };   
  42.     oXmlHttp.send(null);   
  43. }   
  44.   
  45. window.onload = function () {   
  46.     if (1) {   
  47.         checkComment();   
  48.     }   
  49. };  

Comments:

SusanSaysOct 5th, 2007 at 21:30 pm
#4
¶÷£¬¼ä¸ôʱ¼äȷʵ̫¶ÌÁË£¬¶øÇÒÎÒÕâÖÖÆÀÂÛÁ½Ò²Óò»×źܿìµÄ¼ì²â£¬¹þ¹þ
Ñô¹âÄк¢Oct 5th, 2007 at 14:44 pm
#3
¹¦ÄÜ»¹²»´í£¬²»¹ýûÓнṹ»¯¡£ÓÃPrototype¸Äд£¬±ä³ÉÒ»¸öclass¾ÍºÃÁË¡£

var interval = 1000;
ÿÃëÒ»´Î£¬Õâ¸öƵÂʸßÁ˵㣬·ÃÎÊÁ¿Ò»ÉÏÈ¥£¬·þÎñÆ÷¾Í³Ô²»ÏûÁË
СӾSep 30th, 2007 at 0:24 am
#2
²»´í£¬ºÇºÇ
lghSep 29th, 2007 at 23:59 pm
#1
ÓÖÓÐнøÕ¹À²...

Add Comments: