使用我有一个HTML表是这样的:检索JavaScript变量在Perl
<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>
,然后我有触发时,“存档”按钮被击中的每个atempts检索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,所以我可能在这里有更多的问题。任何见解都会很棒。由于
EDITED 我做了一些修改,我的代码。阿贾克斯似乎工作,但我不能告诉我是否仍然援引正确与否。这些脚本位于同一页面上。我仍在检索错误的“notice_id”
你需要设置网址:[看看这里的文档](http://api.jquery.com/jquery.ajax/) –
它虽然是相同的页面。我以为你可以留下空白,如果它是相同的页面 – user3752957