• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using Jquery to Autorefresh Div Issue

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
class Response extends CI_Controller {

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

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


My View 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

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

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.
echo $this->points->get_FighterOneScore();

Sorry for the late reply - I will test his and report back. Thank's for the suggestions!

Thanks for the reply and suggestions. I will test this and report back.

[eluser]Razvan V[/eluser]

did it work?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.