2012-04-17 95 views
1

我很困惑,我必须在rails 3.1中放置ajax回调函数,触发事件beforSend向用户显示字符串“请等待”,并在出现成功时隐藏此字符串。在rails 3.1中放置ajax回调脚本代码的位置?

= javascript_tag "$('#form_remote').bind('ajax:beforSend', function() {$("#mess").show();});" 
%div{:id => 'mess', :style=>"display:none;"} Wait,please 
= form_tag filling_schedule_of_workings_path, :remote => true, :html=>{:id => 'form_remote'} do 
    %p{:style=>"margin:0;width:100%"} 
    = label_tag 'C ' 
    = text_field_tag 'date_begin',nil,:size => 10 
    = label_tag 'по' 
    = text_field_tag 'date_end',nil,:size => 10 
    %br 
    %p{:style=>"margin:0;width:100%"} 
    = label_tag 'Schedule class' 
    = select_tag 'classifier_schedule',@classifier_schedule,:style=>"width:200px;" 
    %p{:style=>"margin:0;width:100%"} 
    = label_tag 'Schedule number' 
    = select_tag 'schedule_number',@schedule_number,:style=>"width:200px;" 
    %div{:style=>"height:25px;border-top:1px solid #CCC;margin:5px 0;"} 
    = submit_tag "Doing", :style => "float:right;" 

这是正常的吗?

请帮忙!

回答

0

我不认为这需要在您的HAML代码中,我通常解决这个问题的方式是在主应用程序JS文件中注册这些事件。例如,如果您想要在AJAX事件开始时出现请稍候动作,则可以执行此类操作:

/* Display a scrim to prevent mouse clicks when an ajax event is occurring. */ 
$.ajaxPrefilter(function(options, originalOptions, jqXHR) { 
    if (!$('#progressIndicator').is(":visible")) { 
     $('#progressIndicator').show(); 
    } 
}); 
$('head').ajaxStop(function() { 
    $('#progressIndicator').hide(); 
}); 

$('head').ajaxComplete(function(event, request, settings) { 
    $('#progressIndicator').hide(); 
}); 
相关问题