我使用AJAX動態獲取評論。這個隱藏的DIV填充了評論和表格,然後顯示出來。該表單用於向當前查看的評論列表添加新評論(通過AJAX返回)。從AJAX表格獲取文本內容
我希望用戶能夠查看DIV中的註釋,然後將註釋從DIV本身添加到DIV中。
一切正常,但我無法獲得評論的文本字段的內容。
我有$('#submit_comment').live('click', function(e) ...
用於檢測AJAX表單提交按鈕。這工作。我只是不能在文本框中獲取字符串...這是非常煩人的,我嘗試了很多方法,如`var comment = $('#new_comment')。val();' - 這不起作用。
我的HTML包括以下內容:
<form id="new_comment" name="new_comment" method="get" action="comments.php">
<input type="hidden" id="trackID" value="' . $track . '">
<input type="text" size="25" id="new_comment_text" /><span style="text-align:right">
<input type="submit" value="Comment" id="submit_comment"/></span>
</form>
它是從comments.php文件中回顯,所有持有浮動DIV中。
如何從AJAX DIV窗體中獲取文本字段的內容?
以下是完整的AJAX調用:
$('#submit_comment').live('click', function(e) {
e.preventDefault();
var comment = $('#new_comment_text').val();
alert(comment);
if (comment != '') {
$('#loading').show();
$('#commentsPanel').hide();
// loading = true
var track = $('#trackID').val();
alert(track);
var data = 'track=' + track + '&isComment=true&comment=' + comment;
alert(data);
$.ajax({
url: 'comment.php',
type: 'GET',
data: data,
cache: false,
success: function (comments_html) {
alert('submit_comment');
$('#commentsPanel').html(comments_html);
$('#commentsPanel').show();
$('#loading').hide();
}
});
}
else {
}
});
重現問題:使用動態內容 – mattsven 2011-03-17 18:25:25
整蠱其實它是具有相同的值作爲ID爲文本區域的名稱。我改變了這一切,它無法正常工作....任何其他信息? – Alex 2011-03-17 18:40:25