我在我的索引頁上有一個表單用於對記錄進行排序,我想爲它添加一些Ajax功能,但由於某種原因,它不會盡快發送我的表單參數添加Ajax的混合。Rails 3 Ajax表單不發送參數
這裏是我的形式:
<div id="sort-options">
<%= form_tag uploads_path, :method => "get", :remote => true do %>
<%= select_tag "sort", options_for_select([["Creation Date", "created_at"], ["File Name", "name"], ["Rating", "rating_average"], ["Downloads", "downloads"]]) %>
<%= select_tag "direction", options_for_select([["Descending", "desc"], ["Ascending", "asc"]]) %>
<%= submit_tag "Sort" %>
<% end %>
</div>
而且我阿賈克斯的javascript:
jQuery(document).ready(function($)
{
$(function() {
$('#sort-options input, .pagination a').live("click", function() {
$.get(this.href, null, null, 'script');
return false;
});
});
});
當我點擊提交按鈕,看看我的Firebug的控制檯來看看發生了什麼很明顯,它成功地調用Ajax和它提供的頁面沒有問題。但是,它完全忽略了發送的參數,並且在重新查詢數據庫時不考慮這些參數。如果我拿出':remote => true'並刪除鏈接到Ajax文件,那麼params會成功發送回索引操作 - 只是沒有Ajax :(
我應該補充一點,Ajax目前適用於分頁我有同一頁上
我附加了一個單獨的提交事件,而不是點擊事件,因此' \t $('#sort-options input')。submit(function(){.....'現在它的作用就像一個魅力。 – Noz 2012-07-18 19:01:05