【问题标题】:Codeigniter 404 Page Not Found The page you requested was not foundCodeigniter 404 Page Not Found 找不到您请求的页面
【发布时间】: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


【解决方案1】:

PHP 找不到这个 "&lt;?php echo base_url();?&gt;home/ajaxsearch?id=" 并且您正在调用 Search.php 控制器,除非您将搜索路径更改为 home/,否则.试试这个:

替换这个:

"<?php echo base_url();?>home/ajaxsearch?id="

有了这个:

"<?php echo base_url();?>search/ajaxsearch?id="

更新答案: 404 消息

对于Search.php 控制器 替换你的 ajaxsearch()

用这个:

function ajaxsearch()
{   
    $id = $this->input->get('id');
    if(isset($id)){
        $this->load->model('Bookmodel'); 

        $data['booktable']=$this->Bookmodel->booktable($this->input->get('id')); 

        echo json_encode($data);
    }
    echo "error";
}

【讨论】:

  • 放一个 echo("test");死();在 ajaxsearch() 的开头并在浏览器上打开它进行测试。告诉我它是否有效。
  • 在控制器中还是?观看次数?
  • 在搜索控制器中
  • 好的尝试访问 search/ajaxsearch?id=test 。在您的浏览器中
  • 还是一样,我看到了'test'
【解决方案2】:

您以错误的格式调用函数。

更改您的网址

"<?php echo base_url();?>home/ajaxsearch?id="

"<?php echo base_url();?>search/ajaxsearch?id="

从此link阅读更多关于codeigniter url路由的信息

【讨论】:

    猜你喜欢
    • 2016-01-12
    • 2013-07-06
    • 2012-12-30
    • 2018-04-18
    • 2014-02-16
    • 2017-10-13
    • 2017-06-19
    • 2013-01-13
    • 2020-12-05
    相关资源
    最近更新 更多