duanbi1983 2011-09-08 20:07
浏览 39
已采纳

jQueryUI自动完成 - 编码问题

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.

  • 写回答

2条回答 默认 最新

  • dscuu86620 2011-09-08 20:40
    关注

    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"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?