所以在我使用Rails 5的应用程序中,我有一个加载器系统,它捕获ajaxSend
和ajaxComplete
来为css中的加载器设置动画。
$(document).bind('ajaxSend', () => {
...
})
$(document).bind('ajaxComplete', () => {
...
})
我的问题很简单,如何用websockets做同样的事情? :)
答案 0 :(得分:0)
function connectToYourChannel () {
// start your animation here
subscription = App.cable.subscriptions.create("YourChannel") {
connected: function () {
// this code will execute when you successfully subscribe
// to your channel;
// end your animation here
}
}
}
BTW:连接过程非常快。在99%的情况下,您不会需要加载消息。