php - jQuery Cookie plugin doesn't really seem to be setting a cookie -


my code sets cookie javascript (using cookie plugin jquery), makes ajax call php script needs read cookie. appears jquery cookie plugin has bug, because php script isn't able read cookie. furthermore, when in resources panel of chrome, don't see cookie under relevant domain. additionally, if set cookie using standard document.cookie method of javascript, cookie appear in resources panel , php script able read it. main reason want use jquery plugin because cookie value i'm setting has line breaks, , jquery cookie plugin seems handle elegantly. it's value going stored in mysql database, , line breaks automatically converted (br) , (p) tags when output. jquery cookie plugin seems give me value want... not in real cookie!

anyway, here's code i'm using. feel free tell me how maintain linebreaks need without using jquery cookie plugin rather trying figure out what's going wrong plugin/my implementation of plugin.

javascript:

$.cookie('flavor','chocolate',{expires:7}); $.get('http://example.com/readcookie.php',function(data){     console.log(data); }); 

readcookie.php

$mycookie = $_cookie['flavor']; echo $mycookie; 

the 'echo' statement above doesn't echo @ all, not empty string. if try var_dump cookie, null. can, however, enter $.cookie('flavor') console , see in fact set. said before, doesn't appear in resources panel of chrome's developer tools, i'm not convinced real cookie... , php script seems agree doubt :)

in code posted, set cookie named 'flavor' on client side, , try read cookie named 'comment' @ server. makes sense me you're not getting anything.

perhaps that's error on part in posting question.

so happens when point ajax request at

'http://' + window.location.host + '/readcookie.php' 

or @ just

'/readcookie.php' 

cookies domain specific.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -