我从Codeigniter逻辑中收到500个内部服务器错误。在控制台中,它看起来像这样
POSThttp://localhost/apluscollege/livesearch/search500(内部服务器错误)jquery.min.js:2
我相信该错误是由于我的.htaccess文件引起的,但我无法找到正确的错误。如果您需要更多代码,请告诉我。
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Livesearch extends CI_Controller
{
function __Construct()
{
parent::__Construct();
$this->load->model('Items');
}
public function index()
{
$this->load->view('livesearch');
}
public function search()
{
$search_data = $_POST['search_data'];
$query = $this->Items->get_live_items($search_data);
foreach ($query as $row):
echo "<li><a href='#'>" . $row->title . "</a></li>";
endforeach;
}
}
这是模型Items.php
<?php
class Items extends CI_Model
{
function get_live_items($search_data)
{
$this->db->select("title,description");
$this->db->from('item');
$this->db->group_start();
$this->db->like('title', $search_data);
$this->db->or_like('description', $search_data);
$this->db->group_end();
$this->db->limit(10);
$this->db->order_by("id", 'desc');
$query = $this->db->get();
return $query->result();
}
}
这是livesearch.php
<form action="<?php echo base_url() . 'tiktok/search' ?>" method="post">
<div class="input-group lrcInputs">
<input type="text" id="search_data" class="form-control search-input" name="search-term" placeholder="What are you looking for?" onkeyup="liveSearch()" autocomplete="off">
<div id="suggestions">
<div id="autoSuggestionsList">
</div>
</div>
<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>
</form>
</div>
<div class="tab-pane fade" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-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">
<input class="form-control" id="lookFor" name="lookfor" 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>
</form>
<script>
function liveSearch() {
var input_data = $('#search_data').val();
if (input_data.length === 0) {
$('#suggestions').hide();
} else {
$.ajax({
method: "POST",
url: "<?php echo base_url(); ?>livesearch/search",
data: { search_data: input_data },
success: function(data) {
if (data.length > 0) {
$('#suggestions').show();
$('#autoSuggestionsList').addClass('auto_list');
$('#autoSuggestionsList').html(data);
}
}
});
}
}
</script>
这是.htaccess文件
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
打开application \ config \ autoload.php文件,然后将database
添加到$autoload['libraries']
数组中。
示例:$ autoload ['libraries'] = array('database');