douran6443 2015-06-29 04:56
浏览 35
已采纳

每10秒重新加载一次javascript代码

I have 3 progress bar on webpage from database data . When user click on load more 3 more progress bar get added from database data.

    <div id="progressBar<?php echo $rec['cid'];?>" class="tiny-green"><div></div></div>
<!-- Some codes are here --->
...
....
.....


<?php
                    $prj= mysql_query("select * from campaign where uid=$uid");
                        $record = array();
                        while($row = mysql_fetch_assoc($prj)){
                            $record[] = $row;
                        }

                    ?>
<script type="text/javascript">     
        <?php foreach($record as $rec){?>

        progressBar(<?php  $perc= $rec['value']*100/$rec['value1']; echo $perc;?>, $('#progressBar<?php echo $rec['cid'];?>'));

        <?php } ?>
</script>

Below is javascript plugin

<script type="text/javascript" src="js/jquery.countdown.min.js"></script>

Now problem is when i add progress bar from load_more button(Which get data by load_more.php file and it insert it on index.php file). i can see the value but progress bar is not creating because code given above not loading after clicking on load_more. So, i want to know is there any way i can reload that code only. So, wherever there is a progress bar control placed it get the display the bar.

  • 写回答

1条回答 默认 最新

  • dsq1982 2015-06-29 11:49
    关注

    update with some modifications, hope it will help you

    $prj= mysql_query("select * from campaign where uid=$uid order by Closing_Date DESC Limit 0,1");
    $result = array('data' => '', 'progress_bar' => array());
    while($row = mysql_fetch_assoc($prj)) {
        $result['data'] .= '<div class="col-sm-1 col-md-4 unique" id="'.$rec['cid'].'">
            <div class="well">
                <div class="media services-wrap55 wow fadeInDown">
                    <a href="view_project/'.$rec['cid'].'/'.$rec['slug'].'"><img class="img-responsive" src="'.$rec['poster'].'"></a><br>
                    <a href="view_project/'.$rec['cid'].'/'.$rec['slug'].'"> <h4 class="media-heading">'.$rec['project_Name'].'</h4></a>
                    <p> by <i>'.$rec['user_name'].'</i></p>
                    <p> '.$rec['short_dis'].'</p>
                    <a class="" href="view_project/'.$rec['cid'].'/'.$rec['slug'].'">More ... </a>
                    <p>
                        <div id="progressBar'.$rec['cid'].'" class="tiny-green"><div></div></div>
                        <h6>'.($rec['view']*100/$rec['view2']).'% ( <i class="fa fa-user"></i>'.$rec['view']. ') '.$rec['view2'].' views.</h6>
                    </p> 
                    <div class="counter-inner"> <div id="example1" data-countdown="'.date("m/d/Y h:i:s", strtotime($rec['Closing_Date'])).'"></div></div><p> <!-- Work on this -->
                    <div class="col-sm-11">
                        <div class="entry-meta">
                            <span><font color="#339933"><i class="fa fa-comment"></i> </font> '.$rec['comment'].' Comments </a></span><!-- Work on this -->
                            <span><font color="#339933"><i class="fa fa-thumbs-up"></i></font> '.$rec['up_count'].' </a></span>
                            <span><font color="#339933"><i class="fa fa-thumbs-down"></i></font> '.$rec['down_count'].' </a></span>
                            <span><font color="#339933"><i class="fa fa-star"></i> </font> '.$rec['fav_count'].' Fav </a></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>';
        $result['progress_bar'][] = array('cid' => $rec['cid'], 'perc' => $rec['value'] * 100 / $rec['value1']);
    }
    
    
    $(document).ready(function() {
        $('#more').click(function() {
            var get_last_post_display = $('.unique-class:last').attr('id'); //get ip last <li>
            $('#more').html('<img src="ajax-loader.gif"');
            $.post('more_prj.php', 'last_id_post='+get_last_post_display, function(html) {
                if(html.data) {
                    $('div').append(html.data);//$('.main-div') ?
                    $('#more').text('Load More Project'); //add text "Load More Post" to button again
                    for(i = 0; i < html.progress_bar.length; i++) {
                        progressBar(html.progress_bar[i]['perc'], $('#progressBar' + html.progress_bar[i]['cid']));
                    }
                } else {
                    $('#more').text('No more Project to load'); // when last record add text "No more posts to load" to button.
                }
            }, 'json');
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,