CodeIgniter Forums
Using Jquery to Autorefresh Div Issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Using Jquery to Autorefresh Div Issue (/showthread.php?tid=53802)



Using Jquery to Autorefresh Div Issue - El Forum - 08-09-2012

[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




Using Jquery to Autorefresh Div Issue - El Forum - 08-09-2012

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


Using Jquery to Autorefresh Div Issue - El Forum - 08-09-2012

[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();



Using Jquery to Autorefresh Div Issue - El Forum - 08-31-2012

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


Using Jquery to Autorefresh Div Issue - El Forum - 08-31-2012

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


Using Jquery to Autorefresh Div Issue - El Forum - 10-16-2012

[eluser]Razvan V[/eluser]
Hi,

did it work?