Help with the Ajax problem Latin and the numbers display fine, but the Russians do not print before such problems were not everywhere I put utf-8, help me in advance thanks

$(window).load(function() { //Π³ΠΎΠ²ΠΎΡ€ΠΈΠΌ скрипту Ρ‡Ρ‚ΠΎ ΠΎΠ½ сработаСт ΠΊΠΎΠ³Π΄Π° вся страница загрузится var ID = [];//ΠΎΠ±Π±ΠΎΠ·Π½Π°Ρ‡Π°Π΅ΠΌ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ для массива $('.btn.btn-primary.btn-lg.width').click(function() {//Π»ΠΎΠ²ΠΈΠΌ ΠΊΠ»ΠΈΠΊ ID.push($(this).data('id'));//записываСм Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ ΠΊΠ»ΠΈΠΊΠΎΠ² Π² массив console.log(ID); });//Ρ‡Ρ‚ΠΎ Π²Ρ‹Π΄Π°Π΄Π΅Ρ‚ консоль Ρ‚ΠΎΡ‡Π½Π΅Π΅ масив $('.btn.btn-primary.btn-lg.width').click(function(e) { //Π»ΠΎΠ²ΠΈΠΌ ΠΊΠ»ΠΈΠΊ $("#basket").show("slow"); // ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅ΠΌ ΠΊΠ°ΠΊ откроСтся Ρ„ΠΎΡ€ΠΌΠ° }); // ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅ΠΌ ΠΊΠ°ΠΊ откроСтся Ρ„ΠΎΡ€ΠΌΠ° $('.compare_basket').click(function(e) { //Π»ΠΎΠ²ΠΈΠΌ ΠΊΠ»ΠΈΠΊ $(".compare_basket").hide("slow"); });// ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅ΠΌ ΠΊΠ°ΠΊ откроСтся Ρ„ΠΎΡ€ΠΌΠ° $('#basket').click(function(e) { //Π»ΠΎΠ²ΠΈΠΌ ΠΊΠ»ΠΈΠΊ $(".compare_basket").show("slow"); console.log(ID); //Ρ‡Ρ‚ΠΎ Π²Ρ‹Π΄Π°Π΄Π΅Ρ‚ консоль $.ajax({ // сам ajax запрос url: "myscript.php", // ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊ Π½Π° php data: {id: ID}, // Π΄Π°Π½Ρ‹Π΅ ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ пСрСдатся type: "POST", // ΠΌΠ΅Ρ‚ΠΎΠ΄ beforeSend: function( xhr ) { xhr.overrideMimeType( "text/plain; charset=utf-8"); }, success: function(response){ $(".col-md-12.ajaxDivId_1").html(response); }, // Ссли запрос ΡƒΠ΄Π°Ρ‡Π½Ρ‹ΠΉ Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌ Ρ‚ΠΎ Ρ‡Ρ‚ΠΎ Π²Π΅Ρ€Π½ΡƒΠ» скрипт php error: function(er){ alert(er); }, // Ссли запрос Π½Π΅ удался Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌ ΠΎΡˆΠΈΠ±ΠΊΡƒ }) .done(function(data) { //ΠΎΡ‚Π»Π°Π΄ΠΎΡ‡Π½Ρ‹ΠΉ запрос ΠΏΠΎ ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌΡƒ заносятся Π΄Π°Π½Π½Ρ‹Π΅ // Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌ ΠΎΡ‚Π»Π°Π΄ΠΎΡ‡Π½ΡƒΡŽ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ }); }); }) 

    1 answer 1

    Try to specify 'contentType' in the call to the AJAX method. For example:

     var ajax_url = < Ρ‚Π²ΠΎΠΉ адрСс >; $.ajax({ data: parameters, type: "POST", url: ajax_url, timeout: 20000, contentType: "application/x-www-form-urlencoded;charset=ISO-8859-5", dataType: 'json', success: callback }); 

    Also specify the encoding on the server. For example, for PHP:

     <?php header('Content-Type: text/html; charset=ISO-8859-5'); ?> 

    In addition, I recommend using the .escape () JavaScript method. You can use it with jQuery, passing the value of the form as follows:

     var encodedString = escape($("#formFieldID").val()); 

    In JavaScript, I can highlight 3 methods for solving problems with encoding:

    1) .escape ();

    2) .encodeURI ();

    3) .encodeURIComponent ().

    More information about each of them I advise you to read in this article .