所以我一直在搜索如何设置它们,最后我结束了这段代码.
@H_502_2@<script>
$('#reportform')
.bind("ajax:success",function(data,status,xhr) {
$('#reportalert').text('Done.');
});
.bind("ajax:error",function(xhr,error) {
$('#reportalert').text('Failed.');
});
</script>
<h2>Review Driver</h2>
<p>Fill out your review of the driver</p>
<div class="hero-unit form-signin" id="reportformdiv">
<%= form_for(@report,html: { id: "reportform" },remote: true,update:
{ success: "response",failure: "error"} ) do |t| %>
<p id="reportalert"></p>
<%= t.text_field :plant_site,placeholder: "Plant Site" %>
<%= t.text_field :route_number,placeholder: "Route Number" %>
<%= t.text_field :driver_name,placeholder: "Driver name if available" %>
<%= t.date_select :date_recorded,html: { class: "input-block-level" } %>
<%= t.text_field :action,placeholder: "Action taken" %>
<%= t.text_area :report_body,placeholder: "What you witnessed",style: "height: 300px;",class: "input-block-level" %>
<%= t.submit "File Report",class: "btn btn-primary btn-large" %>
<% end %>
</div>
但是它不行,我不知道为什么,我确定我做错了,我是新来的RoR,我喜欢这个事实,我可以声明这个遥控器:真实的形式,它的自我,一旦我找出如何设置回调我会很好去:)提前感谢.
解决方法
根据
Rails’ wiki,代码如下:
@H_502_2@<script>
$(document).ready(function(){
$('#reportform').on('ajax:success',function(e,data,xhr){
$('#reportalert').text('Done.');
}).on('ajax:error',xhr,error){
$('#reportalert').text('Failed.');
});
});
</script>
类似的代码在Rails 3.2.14和jquery-rails 3.0.4中为我工作
希望它有帮助.