我有\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>
加载5秒后views\ngoding\load.php
,我得到了代码:
<?php
$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/>";
}
?>
我有控制器controllers\AutoLoadDiv.php
:
我有类似logs\log.php
的日志文件:
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代码无法运行,您可以解析我的代码吗?
答案 0 :(得分:1)
我认为您当前的代码中存在一些错误。我建议您按照以下代码来实现自动重新加载div。
$("#content").load('data.php')
更改为$("#content").load('AutoLoadDiv/getData')
。getData()
来获取日志。(您的load.php代码现在已在此函数中)。控制器
<?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/>";
}
}
}
查看:ngoding /自动加载
<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>