我正在显示我的名字textbox
使用 ajax 自动完成,但我的 ajax URL 不起作用。每次都显示在网络选项卡中
403 禁止。
我尝试过像这样的ajax URL
url:baseUrl + "/index.php/Employee_control/search_with_emp_name",
url:baseUrl +"/Employee_control/search_with_emp_name",
但仍然显示相同的错误。
我的 .htaccess 代码
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
我的基本网址 is $config['base_url'] = 'http://localhost/test/';
My view
<input type="text" class="form_control" name="employee_name" id="employee_name">
自定义.js
var getUrl = window.location;
var baseUrl = getUrl.protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1];
$(document).ready(function() {
$("#employee_name").keyup(function() {
var emp_name = $('#employee_name').val();
$.ajax({
type: "POST",
url:baseUrl + "/index.php/Employee_control/search_with_emp_name",
data: {
emp_name: emp_name
},
success: function(html) {
alert(html);
}
});
});
});
控制器
public function search_with_emp_name(){
echo $emp_name = $this->input->post('emp_name');
$get_result=$this->Employee_model->search_emp_name($emp_name);
print_r($get_result);
}
Model
public function search_emp_name($emp_name){
$this->db->like('firstname', $emp_name, 'both');
$query = $this->db->get('tbl_employee');
$result = $query->result();
if($result)
{
return $result;
}
else
{
return 0;
}
}