Passing utf-8 strings between php and javascript

I'm having trouble passing utf-8 strings to javascript (ajax). I am currently using rawurlencodethe PHP side and unescapethe javascript side.

The problem is in the Latin language and rawurlencodedoes not fully support it.

Is there an alternative or better option?

+3
source share
4 answers

The solution was in the json_encodefunctions. Problems stopped when I added JSON_HEX_APOS|JSON_HEX_QUOT.

Thank!

+2
source

use json_encode in PHP and get answers as JSON (jQuery is useful) ajax is sent to utf-8 by default, so you just need to return utf-8

php utf8_encode (data) ISO-8859-1 .

? , ;)

+1

Javascript escape() (ant unescape()) Unicode (UTF-8). encodeURIComponent() decodeURIComponent().

, :

escape() URI.

+1

php js-, php js? , , .

0

Source: https://habr.com/ru/post/1732911/


All Articles