0

I am making ajax call to the database and every word that is saved in cyrillic is returned like: "[\"\\u043a\\u043d\\u0438\\u0433\\u0430\"]". How can i prevent this ? This line of code should be книга. This is my ajax:

$.ajax({
    method: "POST",
    url: '/admin/site/searchwords',
    /*contentType: "application/json; charset=utf-8",*/
    data: {
        query: string
    },
    success: function (data) {
        var data = JSON.stringify(data);
        console.log(data)
        return false;
    }
});

I commented contentType because it gives me error with it:

PHP Notice 'yii\base\ErrorException' with message 'Undefined index: query'

. Maybe i missunderstood something with them ajax requests. I took a look at another answers but still don't understand how to fix it. The framework is Yii2(if that matters somehow).Thank you in advance!

Jigar Shah
  • 6,143
  • 2
  • 28
  • 41
Toma Tomov
  • 1,476
  • 19
  • 55
  • What if you encode/decode the URI component? – Script47 Sep 11 '17 at 10:30
  • Possible duplicate of [How do I decode a string with escaped unicode?](https://stackoverflow.com/questions/7885096/how-do-i-decode-a-string-with-escaped-unicode) – rndus2r Sep 11 '17 at 10:35
  • It's already unicode encoded and escaped @Script47. He just need the counter part – rndus2r Sep 11 '17 at 10:35
  • I found where my mistake was. I wanted to foreach it like an array so i changed `stringify` to `parse`. Now it works as i expected. – Toma Tomov Sep 11 '17 at 10:37

0 Answers0