Чат куки не работает, как решить проблему? - PullRequest
1 голос
/ 11 февраля 2020

У меня проблема с куки в чате. Если я закрываю чат, куки должны быть записаны, а когда я открываю чат, он должен обновляться. У меня есть код:

var chats = $.cookie('chats');
if (chats == 'on')
{
    $('#chatshow').addClass('hidden');
    $('#chathide').removeClass('hidden');
    $('.chat-body').animate(
    {
        height: '500px'
    }, 1000);
    $('.chat-footer').animate(
    {
        height: '55px'
    }, 500)
}
else
{
    $('#chatshow').removeClass('hidden');
    $('#chathide').addClass('hidden');
    $('.chat-body').animate(
    {
        height: '0px'
    }, 200);
    $('.chat-footer').animate(
    {
        height: '0px'
    }, 200)
};


$(document).on('click', '#chathide', function (e)
{
    e.preventDefault();
    $('#chatshow').removeClass('hidden');
    $('#chathide').addClass('hidden');
    $('.subchat').slideUp();
    $('.chat-body').animate(
    {
        height: '0px'
    }, 1000);
    $('.chat-footer').animate(
    {
        height: '0px'
    }, 500);
    chats = 'off';
    $.cookie('chats', 'off', {
        expires: 365
    })
});
$(document).on('click', '#chatshow', function (e)
{
    e.preventDefault();
    $('#chatshow').addClass('hidden');
    $('#chathide').removeClass('hidden');
    $('.chat-body').animate(
    {
        height: '500px'
    }, 1000);
    $('.chat-footer').animate(
    {
        height: '55px'
    }, 500);
    chats = 'on';
    $.cookie('chats', 'on', {
        expires: 365
    })
});

И в сокете чата я использую var chats = $.cookie('chats');, все должно быть хорошо. Но мой браузер сохраняет куки (я вижу cook ie с параметром off), но когда я закрываю чат, после рефрагирования sh страница чата не закрывается. А в dev.console написано: A cookie associated with a cross-site resource at <URL> was set without the ``SameSite`` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with ``SameSite=None`` and ``Secure``. You can review cookies in developer tools under Application>Storage>Cookies and see more details at <URL> and <URL>..

Где моя ошибка? Что не так?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...