7

साथ बूटस्ट्रैप लटकती से पॉप्युलेट मैं वर्तमान में एक ड्रॉपडाउन कि सूचनाएंरेल: ajax

<li class="notifications dropdown"> 
    <a class="dropdown-toggle" id="dLabel" role="button" data-remote="true" data-toggle="dropdown" data-target="#" href="/notifications"><i class="icon-user"></i> Notifications</a> 
    <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel"> 
    </ul> 
</li> 

उल लटकती खाली है, लेकिन लिंक के क्लिक पर मैं रेल से डेटा के साथ मेनू को भरने के लिए चाहते हैं प्रदर्शित करेगा है।

मैं वर्तमान में notifications.js.erb

$(".nav li.notifications .dropdown-menu").remove(); 
$(".nav li.notifications").append("<%= escape_javascript(render('users/notifications', notifications: @notifications)) %>"); 

आम तौर पर मैं दूरदराज के लटकती लिंक स्थापित करेगा में इस है, लेकिन जब से मैं एक बूटस्ट्रैप की लटकती उपयोग कर रहा हूँ कोई अनुरोध notifications.js.erb के लिए भेजा जा रहा है। मैं मैन्युअल रूप से कोड कैसे कॉल कर सकता हूं?

उत्तर

5

मैं कॉल करने के लिए जावा स्क्रिप्ट कोड जोड़ना होगा:

$(document).ready(function() { 
    $('#dLabel').click(function() { 
     // Only call notifications when opening the dropdown 
     if(!$(this).hasClass('open')) { 
      $.ajax({ 
       type: "GET", 
       url: "/notifications", 
       async: false, 
       dataType: "script" 
      }); 
     } 
    }); 
}); 

आप भी इसे अतुल्यकालिक कर सकता है और अस्थायी रूप से मेनू में एक लोड हो रहा है आइकन डाल ...

संबंधित मुद्दे