我的意思是這是HTML頁面呈現後,我如何通過使用HTML標記ID獲取價值?可以獲取JSON用於從已經由頁面呈現的html標記ID獲取值嗎? json_decode?
例如:通過在我的JS函數中使用td_date來獲取日期的值? 是把頁面上的數據的代碼如下: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;
}
所以在我的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);
}
});
}
然後newMessageDetails.php在我的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));
}
我從JS函數獲得的數據是正確的,但我需要以某種方式知道w什麼是實際上已經在我的網頁上,即已呈現什麼已經不同於什麼json返回和如果數據不同...用新的json數據更新頁面
任何意見?
請看到新的JS代碼..像那樣?謝謝 –
Looak更好。我進一步編輯它,以便您的尋呼機代碼生成的最初tr也有td_id – davidethell
抱歉,但您編輯的行在哪裏? –