开发者

Calling jquery plugin functions on JS callback

开发者 https://www.devze.com 2023-03-16 07:12 出处:网络
I\'ve searched for an answer to this question but haven\'t had any success. I am using the audio.js plugin for audio playback and usually stream files with:

I've searched for an answer to this question but haven't had any success. I am using the audio.js plugin for audio playback and usually stream files with:

// within index.html.erb
audio.load($('.track_info a', clicked_node).attr('data-src'));
audio.play();

When placed in a script block on any html page, it works perfectly. The problem I'm having involved attempting to call the audio plugin through a js callback. Nothing happens when I do the following:

// callback.js.erb
audio.load('<%= "#{@song.sample_url}" %>');
audio.play();

Even when I wrap that with:

$.getScript('/javascripts/audio.js', funct开发者_JS百科ion(){
    alert("Successfully loaded audio.");
)};

Any ideas?

p.s. - The other jquery within callback.js.erb work properly.


Try this:

$.getScript('/javascripts/audio.js', function(){
    audio.load('<%= @song.sample_url %>');
    audio.play();
)};
0

精彩评论

暂无评论...
验证码 换一张
取 消