【发布时间】:2021-11-25 09:39:33
【问题描述】:
目前我正在尝试在codeigniter 的views 文件夹下编写一个AJAX 脚本。为此,我使用<?= $this->section('scripts')?> 在 php 文件中创建了一个脚本。但这样做会给我致命错误:调用未定义的方法 CI_Loader::section()。这是我的完整代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CodeIgniter MVC Basics</title>
</head>
<body>
<form method='post' action="index">
<h1>Customer Details</h1>
<input type="date" name="startDate"/>
<input type="date" name="endDate"/>
<select name="status">
<option>Draft</option>
<option>Unpublish</option>
<option>Let</option>
</select>
<br/><br/>
<button type="button" class="alertbox" name="alertbox">alertbox</button>
</form>
</body>
</html>
<?= $this->section('scripts')?>
<script>
$(document).ready(function(){
$(document).on('click', '.alertbox', function(){
alert("Hello world");
});
});
</script>
<?= $this->endsection()?>
我想要它,以便每当单击按钮时,屏幕上都会弹出一个警报。
编辑我正在从我的控制器加载视图,如下所示:
$this->load->view('crm/test');
以下是错误:
【问题讨论】:
-
你如何加载视图,我的意思是控制器是什么样的?
-
@Don'tPanic 你能看看stackoverflow.com/questions/69446003/…
-
我编辑了您的问题并添加了相关代码 - 您的问题需要包含所有相关信息,此处,而不是分散在其他问题之间。
标签: php ajax codeigniter