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

查看:30
本文介绍了通过 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天全站免登陆