Welcome Guest, Not a member yet? Register   Sign In
Using Jquery to Autorefresh Div Issue
#1

[eluser]doctoroakin[/eluser]
Im fooling around with building a CI app and I love the framework. I am trying to refresh a div in my view every 10 seconds and my code is not working. Does anyone have experience with this?

My Controller
Code:
<?php
class Response extends CI_Controller {

public function left()
{
     $this->load->model('points');
            $data['FighterOneScore'] = $this->points->get_FighterOneScore();
            echo $data['FighterOneScore'];
}

        public function right()
{
     $this->load->model('points');
            $data['FighterTwoScore'] = $this->points->get_FighterTwoScore();
            echo $data['FighterTwoScore'];
}

        
}
?>

My View code
Code:
var auto_refresh = setInterval(
function ()
{
$.get("<?php echo base_url(); ?>response/left",
function(data){ $("#load_score").html($data); } // not sure about fadeIn here!
);
}, 10000); // refresh every 10000 milliseconds

<div id="load_score"></div>

Any help would be greatly appreciated

#2

[eluser]CroNiX[/eluser]
by default CI uses POST, not GET, so try using jQuery's $.post() instead of $.get().
#3

[eluser]CroNiX[/eluser]
As a side, there's really no need to load your result into a variable (which takes memory to store) when all you are going to do is echo it out and not use it anywhere else. Just echo the result and avoid using the variable. You're not sending the data to a view.
Code:
$this->load->model('points');
echo $this->points->get_FighterOneScore();
#4

[eluser]doctoroakin[/eluser]
Sorry for the late reply - I will test his and report back. Thank's for the suggestions!
#5

[eluser]doctoroakin[/eluser]
Thanks for the reply and suggestions. I will test this and report back.
#6

[eluser]Razvan V[/eluser]
Hi,

did it work?




Theme © iAndrew 2016 - Forum software by © MyBB