我有一個小的代碼片斷,它是一個評論系統。當我按下提交按鈕時,我正在嘗試這樣做,表單本身將刷新,評論也會刷新。如何使用jquery重新加載PHP查詢(包含頁面)
我嘗試過使用AJAX,但是當按「提交」時我看不到任何實際啓動的事情。 我的frontpage.php包括播放器的每個元素。 這裏是爲player_comments.php核心:這裏面
<script>
$(document).ready(function() {
var options = {
url: '',
target: '#comment-text', // target element(s) to be updated with server response
type: 'post' // 'get' or 'post', override for form's 'method' attribute
};
// bind form using 'ajaxForm'
$('#song-comment-form').ajaxForm(options);
});
</script>
<?
}
if(isset($userId)) {
/* logged in only */
}
$iComments = 0;
$qComments = $db->query("
SELECT songs_comments.*, user.id AS uId, user.username AS uName, user.avatar AS uAvatar
FROM songs_comments LEFT JOIN user ON songs_comments.userid_from = user.id
WHERE songs_comments.songid = '".$rSong->id."' ORDER BY songs_comments.id DESC");
while ($rComments = $qComments->fetch_object()) {
$showComments .= '
<img src="../'.makeAvatar($rComments->uId,$rComments->uAvatar,50).'" class="avatar float-left" alt>
<div class="comment">
<div class="comment-text">'.$rComments->text.'</div>
<div class="comment-footer">
<a href="/">'.$rComments->uName.'</a> on '.dateStamp($rComments->time).'
</div>
<br style="clear:both;">
</div>
';
$iComments++;
} ?>
<div id="player-song-comments-wrap">
<div id="player-song-comments-heading"><img src="template/images/icons/comments.png" alt> Comments</div>
<div id="player-song-comments-sub-heading">
<?=isset($userId)?'<a href="/" id="show-song-comment-form" class="float-right">Add comment</a>':'<a href="/register.php" class="modal float-right">Add comment</a>'?>
<span id="song-comments-num"><?=$iComments?></span> comments for "<span id="song-comments-title"><?=$rSong->title?></span>"
by <span id="song-comments-artist"><?=$rSong->artist?></span>
</div>
<hr>
<form id="song-comment-form">
<input type="hidden" value="<?=$rSong->id?>" class="song-id">
<textarea class="editor" id="song-comment-textarea"></textarea><br>
<input type="submit" value="Submit"><input type="button" value="Cancel" id="hide-song-comment-form">
<hr>
</form>
<div id="player-song-comments">
<?=$showComments?>
</div>
</div>
我如何使它所以,當我點擊提交,一切都包括被重新加載?
什麼是Ajax請求該目標屬性打電話?它不在文檔中,而是嘗試使用:'success:function(data){$('#comment-text')。html(data);}'並以適當的ajax形式發送請求'$ .ajax .. 。' – CME64 2014-09-26 10:55:34
@ CME64是包含評論的div。 我不擅長AJAX,我是否正好想着進入var選項? – 2014-09-26 10:57:21
這裏是文檔頁面:http://api.jquery.com/jquery.ajax/ – CME64 2014-09-26 10:57:50