KBE
KBE

Reputation: 379

Play video according to response from AJAX GET

I have a server application which returns a HTML 5 video URL on AJAX GET request. How do I render this URL on the client side and play it in video Tag

Upvotes: 1

Views: 2328

Answers (1)

Mohd Asim Suhail
Mohd Asim Suhail

Reputation: 2292

You can easily add a source element inside video tag on successful ajax request. (I have omitted ajax request in this example, but you can easily use the returned URL from AJAX request in the following code)

var video = document.getElementById('video');
var source = document.createElement('source');

source.setAttribute('src', 'http://www.w3schools.com/html/mov_bbb.mp4'); //use your AJAX response URL here.

video.appendChild(source);
video.play();

Demo: https://jsfiddle.net/f990cmem/

Upvotes: 1

Related Questions