Search code examples
javascriptcssruby-on-railsjplayer

jquery getjson for each id dynamically when click - ruby on rails


hi I am working with a music player application there I need to pass my json value of objects in videos controller jquery my jquery code is

  $("#video-play-button").click(function() {
   $.getJSON("../videos.json",function(data){ 
    $.each(data,function(index,video){
      as=JSON.stringify(video)
  myPlaylist3.add({m4v:$(this).attr("video_url"),title:$(this).attr("video_identifier")});
    })
     });
  });

and my html link is like this

<%= link_to 'play' ,  video_path( :id => video.id, :format => :json ) %>

now I want to get json value in json as if I click the x video "../videos/x.json" how to do this?


Solution

  • Use url as Window.location.pathname this will give which link you have to play