从ajax响应更新类

时间:2013-11-06 11:38:10

标签: jquery ajax

我想用我的ajax调用的响应更新类播放,但只更新特定的实例。

audiojs.events.ready(function() {
    var as = audiojs.createAll();

    jQuery(as).ready(function($) {
        $('.ca_podcast_file').each(function(){

            /* cache the container instance in a variable*/
            var $container=$(this);
            /* searching within the container instance for each 
            component insulates multiple instances on page*/
            var $audio= $container.find('audio');

            /*now events will only be bound to this instance*/ 
            $audio.on('playing',function(){
                /* within event callbacks keep searches within the main container element*/                     
                var fileID=$audio.attr('id');
                var data = {file_id: fileID ,security:ChurchAdminAjax.security};

                jQuery.post(ChurchAdminAjax.ajaxurl, { 'action': 'ca_mp3_action','data':   data }, 
                    function(response){

                        $($container,'.plays').html(response);
                    }
                );

            });


        });

    });
});

Html标记

<div class="ca_podcast_file">
   <h3>Hearing God</h3>
       <p><audio class="sermonmp3" id="54" src="http://www.thegatewaychurch.info/wp-content/uploads/sermons/sermon2013-10-27.mp3" preload="none"/></p>
       <p><a href="http://www.thegatewaychurch.info/wp-content/uploads/sermons/sermon2013-10-27.mp3"  title="Hearing God">Hearing God</a></a> <br/>
       Mike Bollinger prophecies over some people and then helps to get going in hearing for God for ourselves <br/>
      <span style="font-size:smaller">The Gateway Church: Mike Bollinger</span> 
      Played: <div class="plays">16</div> times</p>
</div>

...重复播放更多音频文件 - 特定实例将是单击的特定音频元素之一。我的代码更新了正确的代码。我的困难就是这条线

$($container,'.plays').html(response);

我无法弄清楚如何更新该音频实例的播放次数 我该如何让它工作?

1 个答案:

答案 0 :(得分:0)

原来是id是音频标签,并没有覆盖播放类。修改了包含id

然后将html响应行更改为     $(”。起着+ FILEID)html的(响应);