JavaScript / PHP cookie序列化方法? [英] JavaScript/PHP cookie serialization methods?

查看:49
本文介绍了JavaScript / PHP cookie序列化方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,希望将其值存储在Cookie中,因此用户不必每次访问都重新输入表单。 (该表单是用于过滤搜索结果的一些选择。)

I have a form which I would like to store the values of in a cookie so the user doesn't have to re-enter the form every visit. (The form is a few selects to filter search results.)

我希望cookie序列化可以从JavaScript轻松读取(显然将表单设置为 onLoad ),但我也希望能够轻松地从PHP读取cookie(以便我可以使用表单数据来过滤搜索结果)。

I would like for the cookie serialization to easily be readable from JavaScript (obviously to set the form onLoad), but I'd also like to be able to read the cookie easily from PHP (so that I can use the form data to filter search results).

我将如何使用已将 multiple = multiple 设置为select的选择序列化为cookie,并使其易于在JavaScript和PHP中读取?

How would I go about serializing a form with selects that have multiple="multiple" set into a cookie and have it be easily readable in JavaScript and PHP?

请不要讲讲验证,我是在服务器端正确进行的。

Please don't preach about validation, I'm doing that correctly on the server-side.

如果有一个更智能的解决方案,请让我

If there's a smarter solution to my problem please let me know.

顺便说一句:我正在服务器上使用CodeIgniter并使用原型/脚本JavaScript库。

BTW: I'm using CodeIgniter on the server and Prototype/Scriptaculous JavaScript libraries.

解决方案:二手原型的 Object.toJSON( Form.serialize(form,true)) for JavaScript,并使用了PHP的 json_decode(string,bool) 即可从JSON获取PHP中的关联数组。 / p>

Solution: Used Prototype's Object.toJSON(Form.serialize(form, true)) for JavaScript, and used PHP's json_decode(string, bool) to get an associative array in PHP from the JSON.

推荐答案

您可以使用 JSON格式已经以多种语言实现。

You could use the JSON format that is already implemented in several languages.

这篇关于JavaScript / PHP cookie序列化方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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