Answer the question
In order to leave comments, you need to log in
Why is the cookie path not written correctly?
Good afternoon, I wrote a small script, but it does not work quite right.
There is a link like domen/language/support/article/id_article
location.href displays the link correctly, I write down the location.href cookie path, so for some reason it only records domen/language/support/article
And it turns out that you can only vote 1 time, but for me need 1 time per article
Here is the code
var status_useful = getCookie('useful');
var article_id = $(this).attr('data-id');
console.log(location.href);
if (status_useful !== 'yes'){
var data = $(this).attr('data-useful');
$.get('../ajax.php', data, function (res) {
alert(res);
}).fail(function () {
alert('error');
});
var year = 3600 * 24 * 365;
setCookie('useful', 'yes', {
expires: year,
path: location.href
});
}else{
alert('You have already voted');
//alert(location.href);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question