B
B
BonBon Slick2017-10-18 22:31:41
JavaScript
BonBon Slick, 2017-10-18 22:31:41

Ajax request will return °Ð·Ð°Ð½Ð½Ñ‹Ð¹ емейД instead of Cyrillic?

The server is displaying a message in the appropriate language

header('Content-Type: text/html; charset=utf-8');
// или
        header('Content-type: text/plain; charset=utf-8');


 return __('auth.email_not_confirmed');
// вернет
Указанный емейл не подтвержден

    return response()->json(__('auth.email_not_confirmed'));
// вернет
\u0423\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0435\u043c\u0435\u0439\u043b \u043d\u0435 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d


Request goes to npm module axios
window.axios.post(this.formRoute, dataForm)
                    .then((response) => {
....


Module configs:
window.axios.defaults.headers.common = {
    'X-CSRF-TOKEN': window.Laravel.csrfToken, // set by default CSRF token for all request
    'X-Requested-With': 'XMLHttpRequest',
    'Charset': 'utf-8',
};


Query headers
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4,de;q=0.2,uk;q=0.2,da;q=0.2
Cache-Control:no-cache
Connection:keep-alive
Content-Length:438
Content-Type:application/json;charset=UTF-8


response headers
Cache-Control:no-cache, private
Connection:keep-alive
Content-Type:application/json
Date:Thu, 19 Oct 2017 06:42:43 GMT
phpdebugbar-id:b7bd3891919aa3d3a41f3b2017ee2a88
Server:nginx/1.11.9
Set-Cookie:XSRF-TOKEN=eyJp
expires=Thu, 19-Oct-2017 08:42:43 GMT; Max-Age=7200; path=/
Set-Cookie:laravel_session=eyJpdijlhZiJ9; expires=Thu, 19-Oct-2017 08:42:43 GMT; Max-Age=7200; path=/; HttpOnly
Transfer-Encoding:chunked


HTML
<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
// на момент запроса lang="ru"
<head>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="robots" content="all"/>
    <meta name="googlebot" content="index, follow">
...


It's strange, it only works this way through the given module. If you issue a regular adjax, it will return the desired text.

Please tell me how to set up?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Ulanov, 2017-10-18
@antonsr98

what is the encoding in html?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question