php - CodeIgniter 传输控制器的 HTML 标签/字段以查看 - MVC
问题描述
再会!最近,我的HTML 输入/div被放入 Controller对我来说是个问题。我正在寻找一种解决方案,如何将我的字段/输入传输到视图,以便将它们调用到控制器的视图中。所以我可以轻松地使用我的代码。谢谢你
这是我的控制器- 正如您所看到的那样,它仍然divs
存在,所以我只想将它们放到控制器中。
function fetch()
{
$output = '';
$query = '';
$this->load->model('level_model');
if($this->input->post('query'))
{
$query = $this->input->post('query');
}
$data = $this->level_model->fetch_data($query);
$output .= '
<div class="table-responsive">
<table class="table table-bordered table-striped">
<tr>
<th>Courses Year</th>
</tr>
';
if($data->num_rows() > 0)
{
foreach($data->result() as $row)
{
$output .= '
<tr>
<td>'.$row->course_year.'</td>
</tr>
';
}
}
else
{
$output .= '<tr>
<td colspan="5">No Data Found</td>
</tr>';
}
$output .= '</table>';
echo $output;
}
和我的看法
<input type="text" name="search_text" id="search_text" class="form-control">
<div id="result"></div>
阿贾克斯:
<script>
$(document).ready(function(){
load_data();
function load_data(query)
{
$.ajax({
url:"<?php echo base_url(); ?>levels/fetch",
method:"POST",
data:{query:query},
success:function(data){
$('#result').html(data);
}
})
}
$('#search_text').change(function(){
var search = $(this).val();
if(search != '')
{
load_data(search);
}
else
{
load_data();
}
});
});
</script>
<script>
解决方案
对 HTML 内容使用视图文件。
使用这样的东西
$htmlcontent = $this->load->view('viewfile', $data, true);
echo $htmlcontent;
exit();
推荐阅读
- c++ - FLEX/YACC 在操作之间携带变量
- python - 为什么我得到“验证约束无时出错”?
- python - 如何在 Linux 中使用 ctime
- c - 如果 __STDC_IEC_559__ 未定义,那么如何确定 FP(至少部分)符合 IEEE 754?
- swift - 模拟器调试区没有位置选项
- python - Kafka-spark 流不适用于 Jupyter
- c# - 我想在 C# 的函数中打印一个随机数组(如果它不在函数中也可以)。我能怎么做?
- javascript - 网页在 javascript 关闭时错误地重新加载
- c# - 如何在不单击的情况下将子菜单 DropDownItem 设置为 CHECKED?
- python - 如何使相对或绝对导入起作用