admin管理员组文章数量:1291367
I am showing a jQuery overlay when users first visit a particular page
They have a radio button in the overlay that they can click to say they do not wish to see the notification again
I want to set a cookie that the user doesnt want to see the overlay again
Is it possible to set the cookie without refreshing the page?
I was going to make a ajax call back to the server and then set the cookie in the response headers but I guess they wont get set in an Ajax request/response?
Is it safe / OK to set the cookie purely from javascript? Or is that a bad idea?
any other options?
I am showing a jQuery overlay when users first visit a particular page
They have a radio button in the overlay that they can click to say they do not wish to see the notification again
I want to set a cookie that the user doesnt want to see the overlay again
Is it possible to set the cookie without refreshing the page?
I was going to make a ajax call back to the server and then set the cookie in the response headers but I guess they wont get set in an Ajax request/response?
Is it safe / OK to set the cookie purely from javascript? Or is that a bad idea?
any other options?
Share Improve this question edited Apr 15, 2013 at 15:41 ChrisCa asked Apr 15, 2013 at 15:32 ChrisCaChrisCa 11.1k22 gold badges85 silver badges119 bronze badges4 Answers
Reset to default 2There is no reason that an AJAX call cannot set a cookie. It is basically just an HTTP request.
AJAX Requests Get And Set Cookies Like Any Other HTTP Request
You may use jQuery Cookie Plugin.
Some example:
function setCookieFilters() {
var $filtersContent = $(".dynamic-filters");
if ($filtersContent.length > 0) {
if ($filtersContent.css("display") == "none") {
$.cookie("isUsingFilters", "true", { expires: 7 });
}
else {
$.cookie("isUsingFilters", "false", { expires: 7 });
}
}
}
you could also just get/set the cookie in plain old javascript: Create and Store a Cookie
Use this: this shall reload the page.
setcookie($data,$item_data, time()+ (3600));
echo "<script>location.href='index.php'</script>;
本文标签: javascriptSet cookie without page refreshStack Overflow
版权声明:本文标题:javascript - Set cookie without page refresh - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741528612a2383617.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论