Hello, I have a problem with jQuery UI Livesearch - it works perfect with English but do not work with Cyrillic - empty array and I have both in my database. I am using CI 3.1.5 and Firebird 1.5. I guess the problem is in encoding. Here is my code:
My Model:
My controller:
My Ajax:
I tried mb_convert_encoding, iconv, change charset and nothing. The field in the database is win1251.
What I am doing wrong?
My Model:
PHP Code:
public function get_autocomplete($search_data)
{
$data = mb_convert_encoding($search_data, "Windows-1251", "UTF-8");
// var_dump($data);
$query = $this->db1->query("select cl.name
from clients cl
where (cl.name containing '$search_data')");
//var_dump($query);
return $query->result();
}
My controller:
PHP Code:
<?php
class search extends CI_Controller{
public function index()
{
$search_data = $this->input->get("input_data");
$results = $this->search_model->get_autocomplete($search_data);
if(!empty( $results))
{
$jsonData = array(); //Create array
foreach( $results as $row )
{
$jsonData[] = array(
'value' => $row->NAME
);
}
$this->output->set_header("Access-Control-Allow-Origin: *, Content-type: application/json, charset=windows-1251");
echo json_encode($jsonData);
}
}
}
PHP Code:
$(".addClient").each(function() {
$(this).autocomplete({
autoFocus: true,
minLength: 2,
source: function (request, response) {
$.ajax({
url: "<?php echo site_url('search');?>",
scriptCharset: "windows-1251",
data : { 'input_data' : request.term},
contentType: "application/json; charset=windows-1251",
dataType: "json",
success: function (data){
var result = [];
data.forEach(function (value, index) {
result.push({label:value.value, data:value });
});
response(result);
}
});
},
});
});
What I am doing wrong?