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

查看:174
本文介绍了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中轻松地读取cookie序列化(显然设置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的选择的表单序列化为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.

BTW:我在服务器上使用CodeIgniter和Prototype / Scriptaculous javascript库。

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

解决方案: href =http://www.prototypejs.org/api/object/tojson =nofollow noreferrer> Object.toJSON( Form.serialize(form,true)) for javascript,并使用PHP的 json_decode(string,bool) 从PHP中获取关联数组。

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天全站免登陆