这是头部的 jquery :
$(function(){
var $sfield = $('#term').autocomplete({
source: function(request, response){
var url = "<?php echo site_url('admin/get_email'); ?>";
$.get(url, {term:request.term}, function(term){
response($.map(term, function(countries) {
return {
value: aauth_users.email
};
}));
}, "json");
},
minLength: 2,
autofocus: true
});
});
这是我的视图:
<form action="admin/get_email" method="get" accept-charset="utf-8">
<div class="form-group">
<label for="remail">Recipient Email Address</label>
<input type="email" class="form-control" id="term" name="term" placeholder="Email">
</div>
</form
这是我的控制器:
public function get_email()
{
$this->load->model('suggest_email');
$term = $_GET['term'];
$countries = $this->suggest_email->get_email($term);
echo json_encode($countries);
}
这是我的模型:
class Suggest_email extends CI_Model
{
function get_email($term)
{
$this->db->like('email', $term, 'after');
$query = $this->db->get('aauth_users');
return $query->result();
}
}
在chrome控制台中,我可以清楚地看到错误:
http://[::1]/sent/theme/js/jquery.min.js:4 [GET] http://[::1]/sent/index.php/admin/get_email?term=vivo@att.com 500 (内部服务器错误)
答案 0 :(得分:0)
程序找不到jquery和jquery ui的js文件。 请在关闭正文标记后将其添加到页面底部。您需要访问互联网才能使用以下cdn链接。
<script src="https://code.jquery.com/jquery-3.1.0.slim.min.js" integrity="sha256-cRpWjoSOw5KcyIOaZNo4i6fZ9tKPhYYb6i5T9RSVJG8=" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js" integrity="sha256-eGE6blurk5sHj+rmkfsGYeKyZx3M4bG+ZlFyA7Kns7E=" crossorigin="anonymous"></script>