L
L
leni_m2017-07-03 15:07:44
PHP
leni_m, 2017-07-03 15:07:44

Why are cookies buggy?

cookie assignment function:

function setCookie(name, value) {
    document.cookie = name + "=" + value + "; expires=" + "155520";
}

cookie receiving function:
function getCookie(name) {
    var r = document.cookie.match("(^|;) ?" + name + "=([^;]*)(;|$)");
    if (r) return r[2];
    else return "";
}

further I write:
var content = getCookie("invoice-content");
    console.log(content);
var params = {
            content: content
        };
$.post('обработчик',params ,function (data) {
            $('...').html(data);
        });

and in the handler:
print_r($_POST['content']);
and it turns out I change cookies on click, and in the console (console.log) it changes, but the handler (print_r) always
displays the same thing. What could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
leni_m, 2017-07-03
@leni_m

The issue is resolved, everything is correct.

V
Vladimir, 2017-07-03
@djQuery

As the PHP manual teaches us,
In other words, you will see cookies after page reload.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question