Pergunta

I want a auto refresh div in my view page in cakephp 2.4.x. The following are my code. Controller....

public function latestpost(){
    $this->set('posts',$this->Post->find('all',array('limit'=>4)));
}

In my view page index.ctp

<div id="refesh">
  <?php foreach($posts as $post):
          echo $post['Post']['topic'];
  ?>
 </div>

and my jquery code is

<script type="text/javascript">
 $(document).ready(function(){
  //var j = jQuery.noConflict();
 $(document).ready(function()
{
    $("#refresh").everyTime(1000,function(i){
        $.ajax({
          url: "/my_app/posts/latestposts",
          cache: false,
          success: function(html){
            $("#refresh").html(html);
          }
        })
    })
});
 $('#refresh').css({color:"green"});
});
</script>

Only showing the data from the data base. Refreshing is not happening automatically... please any one help me....

Foi útil?

Solução

function refreshCode(){   
  $.ajax({
          url: "/my_app/posts/latestposts",
          cache: false,
          success: function(html){
            $("#refresh").html(html);
          }
        })
}

setInterval(function(){ refreshCode(); }, 1000)

Outras dicas

Try...
function refreshCode(){ 
        $.ajax({
          url: "/my_app/posts/latestposts",
          cache: false,
          success: function(html){
            $("#refresh").html(html);
          }
        })
        setTimeout("refreshCode()",1000);
    } 
    refreshCode();
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top