【问题标题】:autocomplete gives codeigniter3 404 error自动完成给出 codeigniter3 404 错误
【发布时间】:2020-05-16 19:09:11
【问题描述】:

我正在使用和 ajax 和 MySQL 在 Codeigniter 3 中使用 Jquery 自动完成创建搜索栏
这是 Controller College.php 代码

 <?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

<?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

<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 not found的错误。如果需要更多代码或文件,我会提供帮助。

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

代码中的问题是什么...我已经从每个可能的代码角度进行了检查。

【问题讨论】:

标签: php jquery mysql ajax codeigniter


【解决方案1】:

在控制器中,请写

$this-&gt;load-&gt;model('college_model');

而不是

$this-&gt;load-&gt;model('College_model');

加载使用时型号名称应大小写一致

【讨论】:

    猜你喜欢
    • 2015-02-12
    • 2016-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-09
    • 2011-08-26
    • 1970-01-01
    相关资源
    最近更新 更多