I've done a little browsing on this site regarding this topic. And found out that its possible to set php cookies via ajax. But I don't know why I can't set cookies on an ajax called php script. I even set a default value, just to make sure that the cookie is getting something:
setcookie("tradename", 'mono', time()+3600);
setcookie("bus_id", 'loque', time()+3600);
The ajax called php script has mysql queries on it. And they're inserting records into the database. The s开发者_如何学编程etting of cookies happens before the queries.
But I don't know why I'm not getting anything when I use print_r from another page:
print_r($_COOKIE);
I'm using jquery's ajax() function. What do I do to detect what's wrong, please help. Thanks.
You don't need ajax to set cookies from js. Look at "jquery cookie" plugin here, maybe you will like it. Example usage is at the top of jquery.cookie.js.
精彩评论