VideoJS is not defined when load from ajax
I'm using self-hosted videojs 7.1.
I have a page that list a lot of thumbnails, and if you click on any thumbnail, it will load the video source from ajax, and play the video in bootstrap modal dialog.
page HTML
<link href="/css/videojs.min.css" rel="stylesheet">
<script src="/js/videojs.7.1.0.min.js"></script>
<div class="row">
<?php foreach($ids as $id){ ?>
<div class="col-xs-4">
<img src="/path/to/thumbnail-<?php echo $id; ?>.jpg">
<div>some description here</div>
<a class="btn btn-primary btn-play" data-vdoid="<?php echo $id; ?>">Play video</a>
</div>
<?php } ?>
</div>
<div class="modal fade modal-wide" id="dialog-play" tabindex="-1" role="dialog" aria-labelledby="dialogLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body nomargin">
<div id="dialog-play-content">Loading...</div>
</div>
</div>
</div>
</div>
page JS
$(document).ready(function() {
$.ajaxSetup ({cache: false});
$('.btn-play').click(function(){
var vdoid = $(this).data('vdoid');
$.get( "/vdo/player?vdoid="+vdoid, function(data){
$("#dialog-play-content").html(data);
$("#dialog-play").modal('show');
});
return false;
});
});
vdo player HTML
<div id="video-content-<?php echo $vdoid; ?>" class=" ">
<video id="video-player-<?php echo $vdoid; ?>" class="video-js vjs-default-skin vjs-16-9 embed-responsive-item" controls preload="auto">
<source src="/path/to/vdo/<?php echo $vdoid; ?>.mp4" type="video/mp4"></source>
</video>
</div>
vdo player JS
function loadvjs(){
var player = videojs('video-player-<?php echo $vdoid; ?>',{
playbackRates: [1,2,3],
textTrackSettings: false,
});
player.ready(function() {
player.play();
});
}
setTimeout(loadvjs, 1000); //bypass document ready that doesnt fire
The error return was "Uncaught ReferenceError: videojs is not defined" on the second line of the vdo player JS. The HTML5 video still loads and playable in native player.
Above code is able initialize videojs player if the video tag is placed on the page (not from ajax).
I'm try googling around, but couldn't find any answer to my case. Please help, thanks!
jquery video.js
add a comment |
I'm using self-hosted videojs 7.1.
I have a page that list a lot of thumbnails, and if you click on any thumbnail, it will load the video source from ajax, and play the video in bootstrap modal dialog.
page HTML
<link href="/css/videojs.min.css" rel="stylesheet">
<script src="/js/videojs.7.1.0.min.js"></script>
<div class="row">
<?php foreach($ids as $id){ ?>
<div class="col-xs-4">
<img src="/path/to/thumbnail-<?php echo $id; ?>.jpg">
<div>some description here</div>
<a class="btn btn-primary btn-play" data-vdoid="<?php echo $id; ?>">Play video</a>
</div>
<?php } ?>
</div>
<div class="modal fade modal-wide" id="dialog-play" tabindex="-1" role="dialog" aria-labelledby="dialogLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body nomargin">
<div id="dialog-play-content">Loading...</div>
</div>
</div>
</div>
</div>
page JS
$(document).ready(function() {
$.ajaxSetup ({cache: false});
$('.btn-play').click(function(){
var vdoid = $(this).data('vdoid');
$.get( "/vdo/player?vdoid="+vdoid, function(data){
$("#dialog-play-content").html(data);
$("#dialog-play").modal('show');
});
return false;
});
});
vdo player HTML
<div id="video-content-<?php echo $vdoid; ?>" class=" ">
<video id="video-player-<?php echo $vdoid; ?>" class="video-js vjs-default-skin vjs-16-9 embed-responsive-item" controls preload="auto">
<source src="/path/to/vdo/<?php echo $vdoid; ?>.mp4" type="video/mp4"></source>
</video>
</div>
vdo player JS
function loadvjs(){
var player = videojs('video-player-<?php echo $vdoid; ?>',{
playbackRates: [1,2,3],
textTrackSettings: false,
});
player.ready(function() {
player.play();
});
}
setTimeout(loadvjs, 1000); //bypass document ready that doesnt fire
The error return was "Uncaught ReferenceError: videojs is not defined" on the second line of the vdo player JS. The HTML5 video still loads and playable in native player.
Above code is able initialize videojs player if the video tag is placed on the page (not from ajax).
I'm try googling around, but couldn't find any answer to my case. Please help, thanks!
jquery video.js
Are your scripts loaded in the correct order?
– Steven B.
Jan 2 at 20:27
add a comment |
I'm using self-hosted videojs 7.1.
I have a page that list a lot of thumbnails, and if you click on any thumbnail, it will load the video source from ajax, and play the video in bootstrap modal dialog.
page HTML
<link href="/css/videojs.min.css" rel="stylesheet">
<script src="/js/videojs.7.1.0.min.js"></script>
<div class="row">
<?php foreach($ids as $id){ ?>
<div class="col-xs-4">
<img src="/path/to/thumbnail-<?php echo $id; ?>.jpg">
<div>some description here</div>
<a class="btn btn-primary btn-play" data-vdoid="<?php echo $id; ?>">Play video</a>
</div>
<?php } ?>
</div>
<div class="modal fade modal-wide" id="dialog-play" tabindex="-1" role="dialog" aria-labelledby="dialogLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body nomargin">
<div id="dialog-play-content">Loading...</div>
</div>
</div>
</div>
</div>
page JS
$(document).ready(function() {
$.ajaxSetup ({cache: false});
$('.btn-play').click(function(){
var vdoid = $(this).data('vdoid');
$.get( "/vdo/player?vdoid="+vdoid, function(data){
$("#dialog-play-content").html(data);
$("#dialog-play").modal('show');
});
return false;
});
});
vdo player HTML
<div id="video-content-<?php echo $vdoid; ?>" class=" ">
<video id="video-player-<?php echo $vdoid; ?>" class="video-js vjs-default-skin vjs-16-9 embed-responsive-item" controls preload="auto">
<source src="/path/to/vdo/<?php echo $vdoid; ?>.mp4" type="video/mp4"></source>
</video>
</div>
vdo player JS
function loadvjs(){
var player = videojs('video-player-<?php echo $vdoid; ?>',{
playbackRates: [1,2,3],
textTrackSettings: false,
});
player.ready(function() {
player.play();
});
}
setTimeout(loadvjs, 1000); //bypass document ready that doesnt fire
The error return was "Uncaught ReferenceError: videojs is not defined" on the second line of the vdo player JS. The HTML5 video still loads and playable in native player.
Above code is able initialize videojs player if the video tag is placed on the page (not from ajax).
I'm try googling around, but couldn't find any answer to my case. Please help, thanks!
jquery video.js
I'm using self-hosted videojs 7.1.
I have a page that list a lot of thumbnails, and if you click on any thumbnail, it will load the video source from ajax, and play the video in bootstrap modal dialog.
page HTML
<link href="/css/videojs.min.css" rel="stylesheet">
<script src="/js/videojs.7.1.0.min.js"></script>
<div class="row">
<?php foreach($ids as $id){ ?>
<div class="col-xs-4">
<img src="/path/to/thumbnail-<?php echo $id; ?>.jpg">
<div>some description here</div>
<a class="btn btn-primary btn-play" data-vdoid="<?php echo $id; ?>">Play video</a>
</div>
<?php } ?>
</div>
<div class="modal fade modal-wide" id="dialog-play" tabindex="-1" role="dialog" aria-labelledby="dialogLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body nomargin">
<div id="dialog-play-content">Loading...</div>
</div>
</div>
</div>
</div>
page JS
$(document).ready(function() {
$.ajaxSetup ({cache: false});
$('.btn-play').click(function(){
var vdoid = $(this).data('vdoid');
$.get( "/vdo/player?vdoid="+vdoid, function(data){
$("#dialog-play-content").html(data);
$("#dialog-play").modal('show');
});
return false;
});
});
vdo player HTML
<div id="video-content-<?php echo $vdoid; ?>" class=" ">
<video id="video-player-<?php echo $vdoid; ?>" class="video-js vjs-default-skin vjs-16-9 embed-responsive-item" controls preload="auto">
<source src="/path/to/vdo/<?php echo $vdoid; ?>.mp4" type="video/mp4"></source>
</video>
</div>
vdo player JS
function loadvjs(){
var player = videojs('video-player-<?php echo $vdoid; ?>',{
playbackRates: [1,2,3],
textTrackSettings: false,
});
player.ready(function() {
player.play();
});
}
setTimeout(loadvjs, 1000); //bypass document ready that doesnt fire
The error return was "Uncaught ReferenceError: videojs is not defined" on the second line of the vdo player JS. The HTML5 video still loads and playable in native player.
Above code is able initialize videojs player if the video tag is placed on the page (not from ajax).
I'm try googling around, but couldn't find any answer to my case. Please help, thanks!
jquery video.js
jquery video.js
asked Jan 2 at 20:08
JessicaJessica
415
415
Are your scripts loaded in the correct order?
– Steven B.
Jan 2 at 20:27
add a comment |
Are your scripts loaded in the correct order?
– Steven B.
Jan 2 at 20:27
Are your scripts loaded in the correct order?
– Steven B.
Jan 2 at 20:27
Are your scripts loaded in the correct order?
– Steven B.
Jan 2 at 20:27
add a comment |
0
active
oldest
votes
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54012525%2fvideojs-is-not-defined-when-load-from-ajax%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54012525%2fvideojs-is-not-defined-when-load-from-ajax%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are your scripts loaded in the correct order?
– Steven B.
Jan 2 at 20:27