Note that there are some explanatory texts on larger screens.

plurals
  1. POLoop through a jQuery .post function multiple times
    primarykey
    data
    text
    <p>So I am using the jsplayer HTML5 player on my wordpress site, as well as some custom script to load in the next post and replace the old content once the video is finished:</p> <pre><code> $(document).ready(function(){ $(".video-js").bind('ended', function(){ var sStr = "&lt;?php echo get_permalink(get_adjacent_post(true,'',true)); ?&gt;"; var adj_numb = "&lt;?php $adj = get_adjacent_post(true,'',true); $numb = $adj-&gt;ID; echo $numb ?&gt;"; var cur_numb = "&lt;?php echo $post-&gt;ID; ?&gt;"; $.post(sStr, function(data) { var content = $( data ).find( '#post-' + adj_numb); $( "#post-" + cur_numb ).html( content ); var vid = VideoJS.setup( "vid" ); vid.play(); }); }); }); </code></pre> <p>This works great, for exactly one video. It loads in the next video and plays it, but after the 2nd video plays it just stops. I figure this means I have to sort of "reset" all my variables and start again from the beginning of the script, and that it's not doing this because of $(document).ready(function(), as it's already all loaded at this point.</p> <p>Is there a standard way to loop through this script again, and re-set all the variables after its run once?</p> <p>Thanks!</p> <p>EDIT: Rendered JS:</p> <pre><code> $(document).ready(function(){ $(".video-js").live('ended', function(){ var sStr = "http://www.theloniousfilms.com/zachmath/volkswagon/"; var adj_numb = "94"; var cur_numb = "96"; $.post(sStr, function(data) { var content = $( data ).find( '#post-' + adj_numb); $( "#post-" + cur_numb ).html( content ); var vid = VideoJS.setup( "vid" ); vid.play(); }); }); }); </code></pre> <p>HTML:</p> <pre><code>&lt;div class="post-96 post type-post status-publish format-standard hentry category-zachmath" id="post-96"&gt; &lt;h2 id="director"&gt;Zach Math&lt;/h2&gt; &lt;h2 id="post_title"&gt;Orkin - &lt;span id="post_name"&gt; "Hot Tub" &lt;/span&gt; &lt;span id="home"&gt;&lt;a href="http://www.theloniousfilms.com/"&gt;HOME&lt;/a&gt;&lt;/span&gt; &lt;div class="entry"&gt; &lt;div class="video-js-box"&gt; &lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;br /&gt; &lt;video id="vid" class="video-js" width="640" height="360" preload autoplay poster="http://www.theloniousfilms.com/wp-content/uploads/2011/03/poster.jpg"&gt;&lt;br /&gt; &lt;source src="http://d29zgp48wvs9kv.cloudfront.net/orkin.m4v" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /&gt;&lt;br /&gt; &lt;source src="http://d29zgp48wvs9kv.cloudfront.net/orkin.ogv" type='video/ogg; codecs="theora, vorbis"' /&gt;&lt;br /&gt; &lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;br /&gt; &lt;object class="vjs-flash-fallback" width="640" height="360" type="application/x-shockwave-flash"&lt;br /&gt; data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf"&gt;&lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="flashvars" value='config={"playlist":["http://www.theloniousfilms.com/wp-content/uploads/2011/03/poster.jpg", {"url": "http://d29zgp48wvs9kv.cloudfront.net/orkin.m4v","autoPlay":true,"autoBuffering":true}]}' /&gt;&lt;!-- Image Fallback. Typically the same as the poster image. --&gt;&lt;br /&gt; &lt;/object&gt;&lt;br /&gt; &lt;/video&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload