1

所以在我使用Rails 5的应用程序中,我有一个加载器系统,它抓住了ajaxSendajaxComplete的动画,在CSS中加载器。如何使用ActionCable websockets处理js loader?

$(document).bind('ajaxSend',() => { 
    ... 
}) 

$(document).bind('ajaxComplete',() => { 
    ... 
}) 

我的问题很简单,如何用websockets做同样的事情? :)

回答

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 
     } 
    } 
} 

顺便说一句:连接过程非常快。在99%的情况下,您不需要加载消息。