【发布时间】:2014-08-09 02:57:01
【问题描述】:
我有一个类似这样的 html 表格:
<table class="notices-table" width="100%" cellpadding="0" cellspacing="0" border="0">
<% foreach my $notice (@regular_posts) { %>
<form method = "post" id = "post-form-<%= $notice->notice_id()%>">
<tr class = "click-post" href = "<%= $notice->link() %>">
<td><b>Date Posted: </b> <%= '' . (split(/\./, $notice->created()))[0] %><br/>
<b>Title: </b><%= $notice->title() %><br/><br/>
<%= $notice->content() %>
</td>
<td><button class = "archive-button" id="archive-button">Archive</button></td>
</tr>
<input type="hidden" id="action" name="action" value="archive" />
</form>
<% } %>
</table>
然后我有一个javascript代码,当每个尝试检索“notice_id”的“归档”按钮被点击时触发:
$(document).ready(function() {
$('button.archive-button').bind('click', function() {
var id = $(this).attr('id');
var parts = id.split(/-/);
var notice_id = parts[2];
var post_form_id = '#post-form-' + notice_id;
$(post_form_id).submit();
var path_name = window.location.pathname;
$.ajax(path_name, {
type: 'POST'
data: {
'notice_id2' : notice_id
},
success: function(data) {
console.log('/takeNotice called successfully:');
console.log(data);
},
error: function(jqXHR, textStatus, err) {
console.error('/takeNotice call failed:');
console.error(err);
}
});
return false;
});
});
我想将“notice_id”传递给 Perl 脚本,该脚本将使用该 id 从数据库中检索正确的帖子,以便将其存档:
my $cgi = CGI->new;
my $notice_id = $cgi->param("notice_id2");
my $form = $Request->Params();
my $notice;
eval {
$notice = Taskman::Notice->new(notice_id => $notice_id);
};
我对 Perl 和 Javascript/Ajax 还很陌生,所以我可能在这里遇到更多问题。任何见解都会很棒。谢谢
已编辑 我对我的代码做了一些修改。 Ajax 似乎在工作,但我不知道我是否仍在正确调用它。脚本在同一页面上。我仍在检索错误的“notice_id”
【问题讨论】:
-
虽然是同一页。我认为如果它是同一页面,您可以将 url 留空
标签: javascript jquery html ajax perl