Question

I'm currently using jquery.srt.js to display subtitles for some videos that I have.

What I am trying to accomplish is displaying the whole text file of the subtitles in a webpage.

This is what I have in my html document. How can I get the 'data-srt' (a local file) contents?
Thanks

<div id='srt'
     class="srt"
     data-video="video"
     data-srt="sample.srt" />

</div>

EDIT

    $(function()
    {
        $.get($("#srt").data("srt"), function(text) {
            alert(text);
        });
    });

</script>

I tried the above editied version but instead of displaying the subtitle text it gives me:
[object XMLDocument]

Was it helpful?

Solution

I see you're using W3C DOM methods, but your file indicates you're using jQuery. So, the following is shorter using jQuery:

$.get($("#srt").data("srt"), function(text){
  alert(text); // Show the subtitles from the text file.
});

Enjoy!

OTHER TIPS

I'm assuming sample.srt is a text file located on the webserver? You can try performing an ajax call to the text file and using javascript to display the response text to an html element. Use jQuery to perform that AJAX call:

$.ajax(
{
   url: $("#srt").attr("data-srt"),
   success: function(responseText)
   {
       alert(responseText);
   }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top