I am displaying the first name in my textbox
autocomplete using ajax but my ajax URL is not working. It's every time showing in the network tab
403 Forbidden.
I tried ajax URL like this
url:baseUrl + "/index.php/Employee_control/search_with_emp_name",
url:baseUrl +"/Employee_control/search_with_emp_name",
But still showing the same error.
my .htaccess code
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
My base URL is $config['base_url'] = 'http://localhost/test/';
My view
<input type="text" class="form_control" name="employee_name" id="employee_name">
custome.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);
}
});
});
});
Controller
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;
}
}