S
S
Sergey Suntsev2016-04-07 11:09:54
JavaScript
Sergey Suntsev, 2016-04-07 11:09:54

How to fix JSON file encoding?

I have a directory in JSON format. When I embed JSON text through a variable directly into the JS code, then everything is fine, everything works, but if I load it via ajax(POST), from an external file, then for some reason all the Cyrillic text is displayed as question marks.

What encoding should be given to the JSON file in order to have intelligible Russian text? It is not convenient to always flatter the JS code and change the texts.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Taratin, 2016-04-07
@Taraflex

Save the html page itself and scripts in utf8 without BOM.
In html, in head, specify

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">

T
theg4sh, 2016-09-15
@theg4sh

The encoding must match the encoding specified on the page itself with which the response comes, otherwise all ajax responses will use the cast to the default encoding.
Most likely, the sore is treated by adding an HTTP header to the response:
where instead of utf-8 specify the required encoding.
The resulting HTTP response headers can be viewed in the Net tab in FireBug.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question