【发布时间】:2018-04-18 06:42:37
【问题描述】:
我搜索了很长时间,终于在 google 中找到了这个“搜索和查看”教程,但在我尝试运行后,它显示“404 页面未找到”。有没有错误?请帮助我,谢谢。我真的很陌生。
这是控制器 -> Search.php
<?php
function ajaxsearch()
{
if(is_null($this->input->get('id')))
{
$this->load->view('input');
}
else
{
$this->load->model('Bookmodel');
$data['booktable']=$this->Bookmodel->booktable($this->input->get('id'));
$this->load->view('output',$data);
}
}
这是模型 -> Bookmodel.php
<?php
function booktable($search){
$query = $this
->db
->select('jantina','bangsa','agama')
->from('pesakit')
->like('rn',$search)
->or_like('name',$search)
->get();
if($query->num_rows()>0)
{
return $query->result();
}
else
{
return null;
}
}
这是视图-> input.php
<div class="container">
<!-- search box container starts -->
<div class="search">
<div class="space"></div>
<form action="" method="get">
<div class="row">
<div class="col-lg-10 col-lg-offset-1">
<div class="input-group">
<span class="input-group-addon" >BOOK SEARCH</span>
<input autocomplete="off" id="search" type="text" class="form-control input-lg" placeholder="Search Book name or Author " >
</div>
</div>
</div>
<div class="space"></div>
</form>
</div>
<!-- search box container ends -->
<div id="txtHint" style="padding-top:50px; text-align:center;" ><b>Book information will be listed here...</b></div>
</div>
<script>
<script>
$(document).ready(function(){
$("#search").keyup(function(){
var str= $("#search").val();
if(str == "") {
$( "#txtHint" ).html("<b>Book information will be listed here...</b>");
}else {
$.get( "<?php echo base_url();?>home/ajaxsearch?id="+str, function( data ){
$( "#txtHint" ).html( data );
});
}
});
});
</script>
这是输出视图-> output.php
<?php
if(!empty($booktable ))
{
$output = '';
$outputdata = '';
$outputtail ='';
$output .= '<div class="container">
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Jantina</th>
<th>Bangsa</th>
<th>Agama</th>
</tr>
</thead>
<tbody>
';
foreach ($booktable as $objects)
{
$outputdata .= '
<tr>
<td >'.$objects->jantina.'</td>
<td >'.$objects->bangsa.'</td>
<td>'.$objects->agama.'</td>
</tr>
';
// echo $outputdata;
}
$outputtail .= '
</tbody>
</table>
</div>
</div> ';
echo $output;
echo $outputdata;
echo $outputtail;
}
else
{
echo 'Data Not Found';
}
【问题讨论】:
-
什么时候出现找不到页面错误?
-
好的,您可以在浏览器中查看您的 HTML 源代码,然后在 $.get(....) 中查找 url。这说明了什么?
-
$.get("search/ajaxsearch?id="+str, function(data){
-
当您将 URL 放入浏览器以运行此程序时...然后您执行查看源代码(鼠标右键单击 - 查看源代码 - 或类似的东西。)它会向您显示所有 HTML已经生成了你在 .get() 中看到的 URL - 其他人已经回答了这个问题,但我希望你知道如何去看看,看看发生了什么。
标签: php codeigniter xampp