我很困惑,我必须在rails 3.1中放置ajax回调,该回调会触发beforSend事件,向用户显示字符串“请稍候”,并在成功时隐藏该字符串。
= 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;"
这正常吗?
请帮忙!!
最佳答案
我认为这不需要在您的 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();
});
关于javascript - 你把ajax回调脚本代码放在rails 3.1中的哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10194577/