在按钮事件处理程序中设置cookie并从请求中访问它 [英] set cookie in button event handler and access it from request

查看:251
本文介绍了在按钮事件处理程序中设置cookie并从请求中访问它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我对cookie有问题.

我使用具有键/值对的cookie来存储文章.
我有一个添加文章"按钮,将一个键/值对添加到cookie.
当页面重新加载时,我需要访问cookie中的所有值并显示它们.

问题是当单击按钮时,添加了cookie.响应,并且不会出现在请求中,直到下一次重新加载,因为-我猜-页面加载期间正在执行按钮事件处理程序.
如果我添加文章,则在再次执行之前它不会显示在页面上重新加载.

有人知道如何在下次加载页面时使用按钮添加cookie并在Request中添加值.

希望有人能理解我想解释的是什么.

谢谢您的帮助!

Hi all,

I have a problem with cookies.

I use a cookie with key/value pairs for storing articles.
I have a button "Add article" which adds a key/value pair to the cookie.
When the page reloads I need to access all the values in the cookie and display them.

the problem is that when the button is clicked the cookie is added to the Response and will not be present in the Request until another reload since - I guess - the button event handler is being executed during the page load.
If I add an article it won''t show up until I do another reload on the page.

Does anybody have an idea how I can add the cookie with a button and have the value in the Request when the page loads next time.

Hope someone out there understands what I''m trying to explain.

Thank you for your help!!

推荐答案

无论您要显示文章的代码是什么,都可以称为从page_load的2个位置开始,可以调用相同的代码将文章添加到Cookie后,单击按钮事件处理程序.
Whatever code you have to display the articles can be called from 2 places from page_load and the same code can be called in the button event handler after you add the article to your cookie.


这篇关于在按钮事件处理程序中设置cookie并从请求中访问它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆