【问题标题】:auto refresh using jquery in codeigniter在codeigniter中使用jquery自动刷新
【发布时间】:2014-06-04 12:44:28
【问题描述】:

我正在尝试使用 jquery 自动刷新。但我的页面不会自行重新加载

这是我的控制器:

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

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

这是我的观点:

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

这是我的 .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]

有人可以帮助我吗?

谢谢

【问题讨论】:

  • console 中的任何错误? CSRF 开启了吗?
  • 不,控制台没有错误。什么是 CSRF?
  • 有什么理由不只在元标记中这样做吗?

标签: php jquery .htaccess codeigniter


【解决方案1】:

setInterval(); 期望存在一个匿名函数。然后这个匿名函数就可以调用你需要的函数了。

试试这样:

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

【讨论】:

  • 或者干脆setInterval(auto_refresh_function, 500);
猜你喜欢
  • 2010-10-05
  • 1970-01-01
  • 2015-12-11
  • 1970-01-01
  • 2018-08-31
  • 1970-01-01
  • 2011-03-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多