Getting the correct cookie value

I set the cookie through the click event:

    $("#myModal .modal-body a").click(function() {
        document.cookie = 'town='+$(this).text()+'; path=/';
    });

Everything works fine, but when I try to display this value in the html element the next day (if necessary):

<div>
    <?=$_COOKIE['town']?>
</div>

In the browser, I get something like #A=0Gthis in this div. Firebug shows this value #A=0G, but the source data is correct town. What am I doing wrong?

+4
source share
1 answer

There may be an encoding problem, what is the meaning of the beginning town?

You can try setting your cookie like this:

document.cookie = 'town=' + encodeURIComponent($(this).text()) + '; path=/';
0
source

All Articles