jQueryUI autocomplete - encoding problem
I have problem with encoding in jQueryUI Autocomplete. Server side application is PHP and send reply for this query with headers:
Content-Type: application/json, charset=UTF-8
Here is autocomplete code:
$('#city').autocomplete({
source: 'ajax_get_cities.html',
dataType: "json",
minLength:3
});
When I type: kra (expected result is: Kraków) I get reply (copied from Firebug raw reply):
[{"city":"Krak\u00f3w"}]
and autocomplete doesn't display this result.
Database table, field, connection, PHP file, all is UTF-8. Where is problem?Update
This is server side problem, PHP application based on KohanaPHP 2.3.4 framework. Here is code to get and display result:header('Content-Type: application/json, charset=UTF-8');
$开发者_高级运维mModel = new Partners_Model();
$str = $this->input->get('term', true);
$aCities = $mModel->getCitiesAjax($str);
echo json_encode($aCities);
When I disply $aCities array then I get correct string.
The local data can be a simple Array of Strings, or it contains Objects for each item in the array, with either a label or value property or both.
add label property to your json response:
[{"label":"Krak\u00f3w"}]
DOCS: Autocomplete Widget | jQuery UI API Documentation - option "source"
add this to your autocomplete
:
contentType: "application/json; charset=utf-8"
精彩评论