【发布时间】:2012-03-17 21:39:52
【问题描述】:
我的应用程序中有这个 PHP,
<table><tr>
<?php
if($music_interests !== FALSE)
{
$count = 0;
foreach($music_interests as $interest)
{
?>
<td>
<div class="interest inline">
<img src="<?php echo $interest['image']; ?>" alt="<?php echo truncate($interest['name'], 25); ?>" class="interest_img"/>
<p><?php echo truncate($interest['name'], 25); ?></p>
<div class="interest_popup">
<img src="<?php echo $interest['image']; ?>" alt="<?php echo truncate($interest['name'], 25); ?>" class="interest_img left"/>
<div class="right">
<strong><?php echo truncate($interest['name'], 25); ?></strong>
<p>Music<br><?php echo @$interest['num_users']; ?> users have this interest.</p>
<?php echo anchor('my_profile/remove_interest/'.$interest['id'], 'Remove interest', array('class' => 'button red upper rounded_5 small remove')); ?>
</div>
<div class="clear"></div>
</div><!--.interest_popup-->
</div>
</td>
<?php
$count = ($count + 1)%4;
if ($count == 0)
{
echo "</tr><tr>";
}
}
}
?>
如您所见,PHP 创建了一个表,每 4 个<td> 创建一个新行。我现在正在向我的应用程序添加 ajax 功能,但是如果我需要先创建一个新行,然后再添加我的 ajax 请求创建的 <td>,我无法弄清楚我将如何解决。
目前我有这段代码可以将 td 添加到我的表中,
var interest = "<td>" + msg.name + "</td>";
self.parent().children('table').append(interest);
【问题讨论】:
-
您的陈述:“但我无法弄清楚如果我需要先创建一个新行,然后再附加我的 ajax 请求创建的
,我将如何解决。”不是很清楚。您的 ajax 请求的响应是否可靠一致? 我的 ajax 的响应是一致的。
标签: javascript jquery ajax dom-manipulation