Passing utf-8 strings between php and javascript - Stack Overflow

I'm having problems passing utf-8 strings to javascript (ajax). Currently i'm using rawurlenc

I'm having problems passing utf-8 strings to javascript (ajax). Currently i'm using rawurlencode on the PHP side and unescape on the javascript side.

The problem is in latin and rawurlencode doesn't support it fully.

Is there any alternative or any better option?

I'm having problems passing utf-8 strings to javascript (ajax). Currently i'm using rawurlencode on the PHP side and unescape on the javascript side.

The problem is in latin and rawurlencode doesn't support it fully.

Is there any alternative or any better option?

Share Improve this question edited Feb 15, 2010 at 21:37 Gabriel Hurley 40.1k14 gold badges63 silver badges89 bronze badges asked Feb 15, 2010 at 20:50 MissionMission 1,2973 gold badges17 silver badges31 bronze badges 0
Add a ment  | 

4 Answers 4

Reset to default 2

The solution was in json_encode functions. The problems stopped when i added JSON_HEX_APOS|JSON_HEX_QUOT.

Thanks!

use json_encode in PHP and receive responses as JSON (jQuery is helpful) ajax is sent in utf-8 by default, so You just have to return utf-8

php's utf8_encode(data) gets an ISO-8859-1 string as the data argument.

need more suggestions? Tell me where You get the text from ;)

From experience, Javascript's escape() (ant thus unescape()) are not Unicode (UTF-8) friendly. Use encodeURIComponent() and decodeURIComponent() instead.

Anyway, as the docs says:

The escape() function should not be used to encode URIs.

If php is doing the encoding and js decoding whay not simply not encode in php and encode in js as well? Not really an answer so much as a work around i guess.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744539917a4579661.html

相关推荐

  • Passing utf-8 strings between php and javascript - Stack Overflow

    I'm having problems passing utf-8 strings to javascript (ajax). Currently i'm using rawurlenc

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信