S
S
Sergey2015-10-01 01:08:41
JavaScript
Sergey, 2015-10-01 01:08:41

How to run JavaScript code received via AJAX?

Good afternoon!
There is a player for the site jw player 7. Its connection is as follows:

<script src="js/jwplayer7/jwplayer.js"></script>
<script>jwplayer.key="keykeykeykeykeykeykeykey";</script>
<div id="myElement">Loading the player...</div>
<script type="text/javascript">
var playerInstance = jwplayer("myElement");
playerInstance.setup({
    file: "http://www.youtube.com/watch?v=XXXXXX",
    width: 640,
    height: 360,
    title: 'title',
});
</script>


I don’t know in advance how many of these videos I will have, I get it from the database and display the result with ajax. Therefore, on the page I display
<script src="js/jwplayer7/jwplayer.js"></script>
<script>jwplayer.key="keykeykeykeykeykeykeykey";</script>
<div id="videos"></div>

and button. When you click on it, Ajax fills the "videos" block with the following structure:
<div id="myElement1">Loading the player...</div>
<script type="text/javascript">
var playerInstance = jwplayer("myElement1");
playerInstance.setup({
    file: "http://www.youtube.com/watch?v=XXXXXX",
    width: 640,
    height: 360,
    title: 'title',
});
</script>

<div id="myElement2">Loading the player...</div>
<script type="text/javascript">
var playerInstance = jwplayer("myElement2");
playerInstance.setup({
    file: "http://www.youtube.com/watch?v=XXXXXX",
    width: 640,
    height: 360,
    title: 'title',
});
</script>

Etc. But the JavaScript that is passed inside the "videos" block is not processed and the players are not displayed. Something I can’t figure out how to run the resulting JS.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Filimonov, 2015-10-01
@DmitryPhilimonov

Something I did not understand ... You get what from the database? YouTube URLs? So give them to the frontend with Ajax, where you already generate all these players in the code as you like.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question