2

I am getting an error when reading file with ajax, it gets data successfully but firefox throws an error as well:

XML Parsing Error: syntax error
Location: 
http://localhost/xampp/gwp/subtitles/sintel-de.vtt
Line Number 1, Column 1:

I tried adding dataType: "text", but it doesnt help.

subtitle.vtt file:

WEBVTT

0
00:00:00.000 --> 00:00:12.000
This is a subtitle.

1
00:00:18.700 --> 00:00:21.500
This blade has a dark past.

This is an ajax call:

$.ajax({
    url: url//url to subtitle.vtt
    dataType: "text"
}).done(function( data ) {



}).fail(function(jqXHR, textStatus, errorThrown) {

}); 

Error only happens in firefox.

Toniq
  • 4,492
  • 12
  • 50
  • 109
  • here a post that speek vtt file i suppose that you create a new hidden tag video and put your vtt source- link: https://stackoverflow.com/questions/9370260/reading-metadata-from-the-track-of-an-html5-video-using-captionator – C.Fasolin Jul 09 '17 at 13:07
  • You need to have your server send the correct mime header for the file you read – mplungjan Jul 09 '17 at 13:13
  • How do I send a mime header? As you can see from my code, I am just loading a vtt file with ajax. File content loads successfully, but only firefox throws this error (which doesnt affect anything, but it shouldnt be there). – Toniq Jul 09 '17 at 14:29
  • It throws the error because it does not get the mimetype text/plain from the server and then it needs the data to be XML and it is not. Set .vtt as text/plain on the server – mplungjan Jul 10 '17 at 16:14
  • In your `.htaccess` add: ` AddType text/vtt vtt ` - see https://htaccessbook.com/useful-htaccess-rules/ - This fixed it for me. – Avatar Mar 23 '21 at 14:21

0 Answers0