使用我有一個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