0

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.

0

2 Answers 2

2

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"

Sign up to request clarification or add additional context in comments.

1 Comment

In current version, there is also an option to use function as data source :) (downside is that you have to do the search "yourself")
0

add this to your autocomplete:

    contentType: "application/json; charset=utf-8"

1 Comment

doesn't work, this is server side problem. When I try get this address direct in browser I get same result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.