I'm currently trying to load a partial when a button is clicked. So what I do, is add a remote => true, and then a format.js in the controller action that goes to a .js.erb file where I do this:
$('#videospan').html('<%= escape_javascript(render :partial => 'newpartial') %>');
Now videospan already had a different partial, and now I'm adding this partial instead. This works fine when it comes to the html part of it. Now newpartial has some javascript inside it, which unfortunately is not detected. Is it because the html was loaded before the javascript? How can I make it visibile to the HTML? Do I have to define it in the original html file?
Thank you,
One of the javascript methods:
function saveAll()
{
for(key in storedData){
storedData[key].push.apply(storedData[key],[$('#'+key).position().top,$('#'+key).position().left]);
}
$.getJSON('<%= save_answers2_course_lecture_path(@course, @lecture) %>',{"stored":storedData}, function(resp){
redirect()
});
}
So now I'm trying to pass the javascript by adding it to the js.erb as well, so now I have this in the js.erb:
$('#videospan').html('<%= escape_javascript(render :partial => 'newpartial') %>');
pop = Popcorn.youtube( "#youtube", lec ,{ width: 400, controls: 0});
pop.play();
So I want to render the partial which has a #youtube div inside which I then want to use popcorn to add a video to it. Unfortunately, when I add these 3 lines, even the rendering doesn't work..
With firebug, when I check the Response returned, it looks like this:
$('#videospan').html(".........");
pop = Popcorn.youtube( "#youtube", http://www.youtube.com/... ,{ width: 400, controls: 0});
pop.controls( false );
pop.play();
So everything is sent correctly, but how come it's not displayed?
#html()