Hi all, here is my latest code, still doesnt work with ie, but it is
cleaner and neater now, before i continue, i would like to thanks
those who have try to help me..
=D

A variable call "last" is use to track the latest post id, so that i
could use it to query the database and retrieve messages after the
last retrieve one.




Ajax caller
-------------------------------------------------
function getmessage()
{
                var pars = 'last=' + last;

                var myAjaxget = new Ajax.Request('json.php',
                        {
                                method: 'get',
                                parameters: pars,
                                onComplete: loadcomplete
                        });
                window.setTimeout("getmessage()", 2000);
}



Callback
-------------------------------------------------------
function loadcomplete(request) {
  var arrlast = [];
  var elDisplay = $('display');

  if (!elDisplay) return;

  var postTemplate =  new Template(
    '<tr><td><span class="post" id="#{id}">'+
    '</span><span class="date">#{date}</span>'+
    '<p><span class="username">#{name}:'+
    ' </span>#{content}</p><hr/></td></tr>'
  );
console.log(request.responseJSON.message);
  //var response = request.responseJSON.evalJSON();
  var response = request.responseJSON;
 if (!response || (response && !response.message)) return;

  $A(response.message).each(function(m) {
    elDisplay.insert({
      top: postTemplate.evaluate(m)
    })
        arrlast.push(m.id);
  })
  last = arrlast.max();
};



response from Json.php
---------------------------------------------------------
{"message":[{"id":"300","name":"name","content":"ddddd","date":"Mon,
29  Sep, 03:51 PM"}]}




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to