【发布时间】:2012-03-28 18:40:39
【问题描述】:
我正在制作一个动态问题论坛,我只想在用户发布新主题时刷新主题列表,我不想刷新整个页面。这可能吗?
这是我对列出帖子的表格的标记:
<table class="topics">
<tr>
<th width="5%"></th>
<th width="45%"><a href="">Subject</a></th>
<th width="15%"><a href="">Author</a></th>
<th width="10%"><a href="">Replies</a></th>
<th width="10%"><a href="">Views</a></th>
</tr>
<?php foreach ($discussions as $discussion) : ?>
<tr class="alt">
<td><a href=""><img src="<?= site_url('assets/images/featured-posts-icon.png') ?>" /></a></td>
<td><a href="<?= site_url('discussion/test/' . $discussion->stub) ?>" class="subject"><?php echo $discussion->title; ?></a></td>
<td><a href=""><?php echo $discussion->author; ?></a></td>
<td><?php echo $discussion->replies; ?></td>
<td><?php echo $discussion->views; ?></td>
</tr>
<?php endforeach; ?>
</table>
添加新帖子的标记:
<input type="text" name="topic" id="topic" />
<ul class="editor-tools">
<li class="bold"></li>
<li class="italic"></li>
<li class="underscore"></li>
<li class="list"></li>
<li class="quote"></li>
</ul>
<textarea id="thread-content"></textarea>
<a href="" class="button create-discussion">Start discussion</a>
我正在使用 php 获取帖子。现在,当我使用 ajax 添加新帖子时,我有以下代码:
$('a.create-discussion').on('click', function(e){
e.preventDefault();
var title = $('input#topic').val(),
courseId = 1,
message = $('textarea#thread-content').val();
$.ajax({
type : 'POST',
url : ROOT_PATH + 'main/ajaxjson/create_discussion',
data : {title: title, courseId: courseId, message: message},
dataType: 'json'
}).done(function(result){
// do something here?
});
})
【问题讨论】:
-
你的问题到底是什么?
标签: php jquery jquery-selectors page-refresh