what i mean by this is after an html page is rendered, how can i get the value by using the html tag id??
ex: get the value of date by using td_date in my JS function??
below the code that puts the data on the page: listSuccess.php
foreach ($pager->getResults() as $msg)
{
echo "<tr id='td_id' value='$msgId'</tr>";
$date = add_date($msg->getCreatedAt(),$hr=2);
echo "<td class='td_show_contact_item' align='left' id='td_date'>".$date."</td>";
<td align='left' id='td_subject'>
<a href="<?php echo url_for('messagebox/read?cursor=').$cursor ?>" style='color:#ff0000 !important' class='spn_small_red_rbc'><?php echo $msg->getSubject();?></a>
</td>
echo "<td class='td_show_contact_item' align='left' id='td_from'>".$unique_code_from."</td>";
echo "<td id='block_url'>( ".$block_url." )</td>";
echo "</tr>";
++$cursor;
}
so in my JS:
function ax_get_new_msg_details()
{
var mTimer;
$.getJSON('/apps_dev.php/messagebox/newMessageDetails', function(data)
{
var messageExists = $('#' + data.td_id).length > 0;
if (!messageExists)
{
mTimer = setTimeout('ax_get_new_msg_details()',30000);
var str='<tr id="' + data.td_id + '">';
str += "<td class='td_show_contact_item' align='left' id='td_date'>"+data.td_date+'</td>';
str += "<td align='left' id='td_subject'><a href='#' style='color:#ff0000 !important' class='spn_small_red_rbc'>"+data.td_subject+"</a></td>";
str += "<td class='td_show_contact_item' align='left' id='td_from'>"+data.td_from +"</td>";
//str += "<td id='block_url'>"+data.block_url+"</td>";
str +='<tr>';
var tbl = $('#td_date').parents('table');
$(tbl).append(str);
}
});
}
then newMessageDetails.php in my actions.class.php
public function executeNewMessageDetails(sfWebRequest $request)
{
$profile_id = $this->getUser()->getAttribute('profile_id','zero');
$new_msgs = RcMessageBoxTablePeer::getNewMessages($profile_id);
if (count($new_msgs) >= 1)
{
foreach ($new_msgs as $row)
{
$date = $row->getCreatedAt();
$subject = $row->getSubject();
$from = $row->getProfileIdFrom();
$id = $row->getId();
$uc_record = RcProfileTablePeer::getById($from);
$uc_from = $uc_record->getUniqueCode();
//$block_url = 'Block User',"blocklist/block?unqiue_code=$uc_from",'class=link_medium_blue');
}
$output = array("td_date" => $date, "td_subject" => $subject, "td_from" => $uc_from, "td_id" => $id);
}
else
$output = "";
return $this->renderText(json_encode($output));
}
the data that i get from the JS function is correct but i need to somehow know that what is actually already on my page ie what was rendered already differs from what json returns and if data differs…update the page with the new json data
any advice?
Why not include your td_id in your tr tag and just compare the incoming id with the existing id?
Then in your update put this if condition around your code: