在我的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