2012-04-17 51 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(); 
}); 
相關問題