在我的Rails 3.1應用程序中,我有一個Jquery對話框,點擊時彈出,並且裏面有一個提交按鈕。我做了一些嘗試,使這個'提交'按鈕阿賈克斯。所以當它被點擊時它會更新預約時間和日期。我有以下代碼:單擊提交按鈕時觸發Ajax調用
<% if @booking.id and current_user.is_booking_manager? %>
<button id="confirm_appointment">
test confirmation
</button>
<div style="display:none;">
<div id="confirm_appointment_dialog" title="Test Confirm Booking">
<%= form_for @booking, :url => booking_confirmation_path(@booking), :remote => true do |f| %>
<%= f.hidden_field :id %>
<%= f.datetime_select :confirmed_appointment %>
<br />
<b>Clear provisional appointment:</b><%= check_box_tag "make_unexpected" %>
<br />
<%= f.submit :class => 'submit_me' %>
<% end %>
</div>
</div>
<% end %>
的application.js
$('.submit_me').bind('change',
function() {
$(this).parents('form:first').submit();
});
有我丟失的東西
重新加載頁面後會更新嗎?在這種情況下,您需要定義一個create.js.erb或一個update.js.erb並在那裏更新頁面。 此外,據我所知,綁定代碼並不是必需的,因爲:在您的表單實例化中:remote => true已經使表單「ajax」已經 – 2012-03-13 11:35:53
是的,它在頁面重新加載後更新 – David 2012-03-13 11:36:38
所以你說我應該創建一個update.js.erb並把我的JavaScript裏面? – David 2012-03-13 11:37:01