通过AMP页面上的API访问Cookie [英] Access cookies through an API on AMP page

查看:141
本文介绍了通过AMP页面上的API访问Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将页面转换为google AMP,并且需要访问cookie才能设置部门视图.我正在考虑为此创建一个API.

I am converting a page to google AMP and need to access cookies to set a view of a division. I am thinking of creating an API for this.

API只会以JSON格式返回我域中可用的所有cookie.我将使用<amp-state>组件访问API,并存储返回的JSON.然后将根据此状态采取措施.

The API will just return all the cookies available on my domain in JSON format. I will hit the API using <amp-state> component and store the returned JSON. Then will take actions according to this state.

这是在AMP中使用的有效方法吗?是否有任何安全流程?

Is this a valid approach to use in AMP? Is there any security flow in this?

推荐答案

在这种情况下,使用amp-list是正确的方法. amp-list向您的服务器发出请求,该服务器可以读取cookie并返回适当的JSON响应.然后,您可以使用amp-mustache渲染amp-list内的表单/按钮.

Using amp-list is the right approach in this case. amp-list makes a request to your server, which can read the cookie and return an appropriate JSON response. You can render then the form / button inside the amp-list using amp-mustache.

此示例演示了如何执行此操作: https://ampbyexample.com/advanced/favorite_button/.

This samples demonstrates how to do this: https://ampbyexample.com/advanced/favorite_button/.

这篇关于通过AMP页面上的API访问Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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