jquery json的字符

Mik*_*ikk 7 unicode jquery base64 getjson

我正在使用jquery $ .getJSON来检索城市列表.

一切都很好,但我来自爱沙尼亚,我们正在使用像õ,ü这样的角色.ä,ö.

当我将这样的字母传递给回调函数时,我不断得到空字符串.我试过base64编码(服务器端)-decode(jquery base64插件)字符串(我认为这是一个好主意,只要我可以用PHP压缩页面,所以我不必担心带宽),但是通过这种方式,我最终得到了一些随机的中文符号.

什么是这个问题的最佳解决方法.

谢谢.

And*_*ndy 4

您需要utf8_encode()输出数据。无需在客户端将编码设置为 UTF-8,因为它已经是默认编码。

\n\n
<?php\n    if( isset( $_GET['json'] ) ) {\n\n        die( json_encode( array( 'text' => utf8_encode( '\xc3\xb5, \xc3\xbc. \xc3\xa4, \xc3\xb6' ) ) ) );\n    }\n\n    include_jquery(); # this outputs jquery include\n>?\n\n<script>\n\n    $.getJSON( 'this_file.php', { 'json': 1 }, function( data ) {\n        console.log( 'data', data );\n    });\n\n</script>\n
Run Code Online (Sandbox Code Playgroud)\n