1

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

3
  • any error in the console ? is CSRF on ? Commented Jun 4, 2014 at 12:57
  • no, there is no error in console. what is CSRF? Commented Jun 4, 2014 at 13:34
  • Any reason not to just do it in a meta tag? <meta http-equiv="refresh" content="5" > Commented Jun 4, 2014 at 22:21

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

1 Comment

or simply setInterval(auto_refresh_function, 500);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.