Reputation: 39
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....
Upvotes: 0
Views: 2344
Reputation: 2989
Try...
function refreshCode(){
$.ajax({
url: "/my_app/posts/latestposts",
cache: false,
success: function(html){
$("#refresh").html(html);
}
})
setTimeout("refreshCode()",1000);
}
refreshCode();
Upvotes: 0
Reputation:
function refreshCode(){
$.ajax({
url: "/my_app/posts/latestposts",
cache: false,
success: function(html){
$("#refresh").html(html);
}
})
}
setInterval(function(){ refreshCode(); }, 1000)
Upvotes: 1