views:

146

answers:

3
$(document).ready(function(){
var refreshId = setInterval(function() {
 periodicRefresh();
}, 9000);
})

.

function periodicRefresh()
{
    $.ajax({
        type: 'GET',
        url: 'include/ajaxActions.php',
        data: "action=displayLastEvent",

        success: function(msg){
         var newid = $(msg).attr("id");
                    current = $("#list tr:first").get(0).id;
                    if(newid != currentfirstrow){
                        $("#list").prepend(msg);
             lastrow = current-19;
             $('#'+lastrow).remove();
                    }
        }
    });
}

Here is an example of what the table row looks like:

<tr id="5094"  style="background:White;">
  <td class="tdstd">
  </td>
</tr>
+1  A: 

At first ids aren't allowed to be numbers. They should start with a letter, then followed by a number. So you need to follow a different naming convention for your ids.

I am not sure if that's what you are asking for, but you can get the id of the first row with something like this:

$("table tr:first").get(0).id
kgiannakakis
+3  A: 

That's a little hard to answer, without knowing how the XML that is returned from "ajaxActions.php" and your AJAX call is formatted. Also, I'm assuming that "currentfirstrow" is a global javascript variable accessible inside any function?

function periodicRefresh()
{
    $.ajax({
        type: 'GET',
        url: 'include/ajaxActions.php',
        data: "action=displayLastEvent",

        success: function(xml){
      var newfirstrow = $(xml).find("name_of_xml_node_that_contains_newly_returned_id").text();
      if(newfirstrow != currentfirstrow){
       //do add new row()
      }
        },
}
WesleyJohnson
the output of ajaxActions.php is only: <tr id="5094" style="background:White;"> <td class="tdstd"> </td</tr>
mnml
but I can also format it as a XML
mnml
Ah okay, so you're just outputting html essentially. Good to know, let me think about it for a bit.
WesleyJohnson
Thanks I found how to do that part with html and its edited in the my post
mnml
Okay, well then I would assume that you could just prepend the returned HTML to the table. This should add the html immediately after the <table> tag. I think? Sorry, it's been a while. :Dif(newfirstrow != currentfirstrow) { $("#TableID").prepend(msg);}
WesleyJohnson
nice I'm trying all this and I update my post in a few sec
mnml
Looks like it's working perfectly thanks for the help
mnml
Excellent, glad we got it all sorted out. :)
WesleyJohnson
+1  A: 

Check this blog post. http://deostroll.spaces.live.com/blog/cns!428DAD5E3A907C31!259.entry

deostroll