首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自动完成给出codeigniter3 404错误

自动完成给出codeigniter3 404错误
EN

Stack Overflow用户
提问于 2020-01-31 05:30:00
回答 1查看 76关注 0票数 0

我正在使用Codeigniter 3中的Jquery自动完成和ajax和MySQL创建一个搜索栏

这里是控制器College.php代码

代码语言:javascript
复制
 <?php
        defined('BASEPATH') OR exit('No direct script access allowed');

        class College extends CI_Controller
        {
            public function __construct() {
                parent::__construct();
                $this->load->model('College_model');
            }

            public function index() {
                $this->load->view('college_view');
            }

            function get_autocomplete() {

                if (isset($_GET['term'])) {
                    $result = $this->college_model->search_college($_GET['term']);

                    if (count($result) > 0) {
                        foreach ($result as $row) {
                            $arr_result[] = array(
                                'name' => $college_name,
                                'description' => $row->college_description,
                            );
                            echo json_encode($arr_result);
                        }
                    }
                }
            }
        }
    ?>

我是College_model.php

代码语言:javascript
复制
<?php
        class College_model extends CI_Model
        {
            function get_all_college() {
                $result = $this->db->get('college');
                return $result;
            }

            function search_college($name) {
                $this->db->like('college_name', $name, 'both');
                $this->db->order_by('college_name', 'ASC');
                $this->db->limit(10);
                return $this->db->get('college')->result();
            }
        }
    ?>

这是视图页college_view.php

代码语言:javascript
复制
<div class="tab-content py-3 px-3 px-sm-0 m-auto" id="nav-tabContent">
        <div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
            <form action="http://vufind.carli.illinois.edu/vf-aru/Search/Home" method="get" role="search" target="vufind" name="searchForm">
                <div class="input-group lrcInputs">
                    <input value="1" name="start_over" type="hidden">
                    <label></label>
                    <input class="form-control" id="college" name="college" type="text" placeholder="Search for books, ebooks, & media">
                    <div class="input-group-btn">
                        <button class="btn btn-success lrcSearchButton" type="submit"><i class="fa fa-search" aria-hidden="true"></i></button>
                    </div>
                </div>
                <script type="text/javascript">
                    $(document).ready(function () {
                        $('#college').autocomplete({
                            source: "<?php  echo site_url('college/get_autocomplete'); ?>",
                            select: function (event, ui) {
                                $('[name="college"]').val(ui.item.name);
                            }
                        });
                    });
                </script>

如何删除404找不到的错误。如果需要更多的代码或文件,我会提供帮助。

作为GET http://localhost/apluscollege/college/get_autocomplete?term=as 404 (not found) jquery.min.js,我在chrome控制台中出错。

代码中的isuue是什么,...I从代码的每一个可能的角度进行了检查。

EN

回答 1

Stack Overflow用户

发布于 2020-02-09 08:36:58

在控制器中,请写

$this->load->model('college_model');

而不是

$this->load->model('College_model');

在加载和使用模型名称时,应该是相同的情况。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59998381

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档