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%的情況下,您不需要加載消息。