lamfete
lamfete

Reputation: 151

auto refresh using jquery in codeigniter

I'm trying to auto refresh using jquery. but my page won't reload by itself

Here is my controller:

class Count_controller extends CI_Controller {
  public function index() 
  { 
    $this->load->view('count_view', @a);
  }

  public function table()
  {
    $a = rand(1000, 5000);
    echo $a;
  }
}

And here my view:

<html>
  <head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript">
      setInterval("auto_refresh_function();", 500);
        function auto_refresh_function() {
          $('#load_content').load('http://demo1.com/demo/count_controller/table');
        }
</script>
  </head>

  <body>
    <div id="load_content">Loading</div>
  </body>
</html>

Here is my .htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php|static|js|css|gif|png|jpg|robots\.txt|html)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

can somebody help me?

thank you

Upvotes: 1

Views: 8576

Answers (1)

MonkeyZeus
MonkeyZeus

Reputation: 20737

setInterval(); expects an anonymous function to be present. This anonymous function can then call the function you need.

Try it like this:

setInterval(function(){auto_refresh_function();}, 500);

Upvotes: 2

Related Questions