[英]How To Auto Load div content in PHP codeigniter?
我有視圖\\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/>";
}
?>
我有 Controller 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 代碼無法運行,你能解決我的代碼嗎?
我認為您當前的代碼中存在一些錯誤。 我建議你按照下面的代碼來實現自動重新加載 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.