在RoR中的ajax页面请求期间触发JS加载消息的最简洁方法是什么

时间:2022-10-13 15:57:28

I am building a new application in Rails 3 and want to implement a "Loading" message that is displayed when an ajax request is fired off and hidden when the response comes back.

我正在Rails 3中构建一个新的应用程序,并希望实现一个“加载”消息,该消息在ajax请求被触发时显示,并在响应返回时隐藏。

I would like to keep it DRY and only specify this functionality in one place, with the ability to override the functionality selectively (for instance, always display the loading message when navigating around the site, but suppress it for things like predictive search).

我想保持DRY并且只在一个地方指定此功能,能够有选择地覆盖功能(例如,在浏览网站时始终显示加载消息,但是对于预测搜索等内容禁止加载消息)。

I'm standardizing on JQuery for this project, although I'm guessing the answer won't be library specific.

我正在为这个项目标准化JQuery,虽然我猜测答案不会是特定于库的。

Thanks in advance for your feedback!

在此先感谢您的反馈!

1 个解决方案

#1


2  

jQuery has global ajax handlers such as ajaxStart and ajaxComplete. Once set they fire for all ajax calls.

jQuery具有全局ajax处理程序,例如ajaxStart和ajaxComplete。一旦设置,它们就会激活所有ajax调用。

You can override these global ajax handlers by setting the global property to false on subsequent ajax calls.

您可以通过在后续的ajax调用中将global属性设置为false来覆盖这些全局ajax处理程序。

#1


2  

jQuery has global ajax handlers such as ajaxStart and ajaxComplete. Once set they fire for all ajax calls.

jQuery具有全局ajax处理程序,例如ajaxStart和ajaxComplete。一旦设置,它们就会激活所有ajax调用。

You can override these global ajax handlers by setting the global property to false on subsequent ajax calls.

您可以通过在后续的ajax调用中将global属性设置为false来覆盖这些全局ajax处理程序。