There is a project page on which the user:
1. Select a city, displaying the event plan.
2. Selects the event time at the event, displaying the description of the individual event.

In paragraph 2, the formula is used:

... newContent += times[loc][i].title.replace(/ /g, '-') + '">'; .. 

which loads the event description by the identifier obtained from the title element of the JSON file with the event event names (here: 3D modeling):

 { "CA": [ { "time": "9:00", "title": "3D-ΠΌΠΎΠ΄Π΅Π»ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅" }, ... 

looks for the corresponding identifier (i.e., <code>3D-ΠΌΠΎΠ΄Π΅Π»ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅</code> ) in the html file and displays the description on the page (in this case it does not work, because the identifier in Latin is Intro-to-3D-Modeling ):

 ... <div id="Intro-to-3D-Modeling"> <h3>3D-ΠΌΠΎΠ΄Π΅Π»ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅</h3> <p>ОписаниС</p> </div> ... 

The problem is that if in the JSON file the text in the title elements is specified in Cyrillic, descriptions are not displayed. If the Latin - everything works. JSON Latin can not write, because the same text is displayed on the web page. Naturally, I can not write the values ​​of the attributes id in Cyrillic. How to be?

  • Try instead of the full name to use a certain ID, well, for example, calculate MD5 from the Cyrillic name. - chernomyrdin
  • How to implement it? Tuplya - Spliff Guru
  • and how do you get information from a JSON file? Cyrillic texts through [getJSON ()] [1] are perfectly added to the page [1]: api.jquery.com/jquery.getJSON - MasterAlex
  • And what encoding is used in json-file and in html? - sercxjo
  • In HTMl, utf-8 is explicitly specified and the file is saved in utf-8. Json is saved in utf-8, not explicitly indicated. The problem is that in JSON the title values ​​are specified in Russian. Since the title is in Russian, she is also looking for id in Russian. Here is the problem, as id in English - Spliff Guru

2 answers 2

Specify the encoding for the returned JSON in the HTTP header:

 Content-Type: application/json, charset=utf-8 

    One solution would be to use data attributes and search for them. For example:

     <div id="Intro-to-3D-Modeling" data-title="3D-ΠΌΠΎΠ΄Π΅Π»ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅"> <h3>3D-ΠΌΠΎΠ΄Π΅Π»ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅</h3> <p>ОписаниС</p> </div> 
    • Although the link can find the answer to the question, it is better to point out the most important thing here, and give the link as a source. If the page to which the link leads will be changed, the response link may become invalid. - From the queue of checks - Denis
    • @Denis, thank you, added - Pavel Tetyuyev