如何在PHP codeigniter中自动加载div内容?

如何在PHP codeigniter中自动加载div内容?,php,jquery,codeigniter,Php,Jquery,Codeigniter,我有view\views\ngoding\AutoLoad.php: <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $(document).ready(function(){ setInterval(function(){ $("#content").load(

我有view
\views\ngoding\AutoLoad.php

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
setInterval(function(){
$("#content").load('data.php')
}, 5000);
});
</script>

<style>
#content{
background-color: #00A1E0;
font-size: 24px;
font-weight: bold;
padding-top : 10px;
color : #fff;
min-height: 200px;
}
#content,h1 {
    text-align: center;
}
</style>

<title>Auto Load Page in Div using Jquery</title>
</head>
<body>
    <h1>Auto Load Page in Div</h1>
    <div id="content">Please wait....</div>
</body>
</html>
ERROR - 2018-09-17 06:51:03 --> Severity: Warning --> Illegal string offset 'Catatan' /var/www/html/minilos/application/views/minilos/form_akkk.php 483
ERROR - 2018-09-17 06:51:03 --> Severity: Warning --> Illegal string offset 'Catatan' /var/www/html/minilos/application/views/minilos/form_akkk.php 483
ERROR - 2018-09-17 06:51:03 --> Severity: Warning --> Illegal string offset 'Rekomendasi' /var/www/html/minilos/application/views/minilos/form_akkk.php 502
我有Controller
controllers\AutoLoadDiv.php

我有这样的日志文件
logs\log.php

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
setInterval(function(){
$("#content").load('data.php')
}, 5000);
});
</script>

<style>
#content{
background-color: #00A1E0;
font-size: 24px;
font-weight: bold;
padding-top : 10px;
color : #fff;
min-height: 200px;
}
#content,h1 {
    text-align: center;
}
</style>

<title>Auto Load Page in Div using Jquery</title>
</head>
<body>
    <h1>Auto Load Page in Div</h1>
    <div id="content">Please wait....</div>
</body>
</html>
ERROR - 2018-09-17 06:51:03 --> Severity: Warning --> Illegal string offset 'Catatan' /var/www/html/minilos/application/views/minilos/form_akkk.php 483
ERROR - 2018-09-17 06:51:03 --> Severity: Warning --> Illegal string offset 'Catatan' /var/www/html/minilos/application/views/minilos/form_akkk.php 483
ERROR - 2018-09-17 06:51:03 --> Severity: Warning --> Illegal string offset 'Rekomendasi' /var/www/html/minilos/application/views/minilos/form_akkk.php 502
我有这样的代码自动加载div 5秒,我想自动加载内容
views\ngoding\load.php


为什么我的自动加载div的代码无法运行,您能解决我的代码吗?

我认为您当前的代码中有一些错误。我建议您按照下面的代码来实现自动重新加载div

  • 我已将视图中的
    $(“#content”).load('data.php')
    更改为
    $(“#content”).load('AutoLoadDiv/getData')
  • 我还在您的控制器中添加了
    getData()
    ,以获取日志
  • 控制器

    <?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    
    class AutoLoadDiv extends CI_Controller {
    
        public function __construct()
        {
            parent::__construct();
        }
    
        public function index()
        {
            $this->load->view('ngoding/AutoLoad');  
        }
    
        public function getData() {
            $err = file_get_contents("application\logs\log.php");
            echo preg_replace(array('/(^|\R)ERROR\s*-\s*/', '/(^|\R)(.*?)\s*-->\s*/'), array('$1', '$1$2 '), $err);
            echo "<br>";
            echo "Content akan load selama 5 detik";
    
            for ($i = 0; $i <=10; $i++) {
                echo $i. "<br/>";
            }
        }
    
    }
    
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
        $(document).ready(function(){
        setInterval(function(){
        $("#content").load('AutoLoadDiv/getData')
        }, 5000);
        });
    </script>
    
    <style>
    #content{
        background-color: #00A1E0;
        font-size: 24px;
        font-weight: bold;
        padding-top : 10px;
        color : #fff;
        min-height: 200px;
        }
        #content,h1 {
            text-align: center;
        }
    </style>
    
    <title>Auto Load Page in Div using Jquery</title>
    </head>
    <body>
        <h1>Auto Load Page in Div</h1>
        <div id="content">Please wait....</div>
    </body>
    </html>
    

    可能重复的您能解释一下当您尝试执行它时您得到了什么输出吗?它将打印日志文件的内容,每5秒一次如果输入新数据,它将加载并添加到顶部row@DevoAvidiantoP我已经实现了相同的。。检查答案。。