如何将javascript对象从一个页面传递给另一个页面 [英] How to pass javascript object from one page to other

查看:126
本文介绍了如何将javascript对象从一个页面传递给另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将javascript对象从一个页面传递到其他页面,这样任何人都可以告诉我该怎么做?

I want to pass javascript object from one page to other page so anyone can tell me how to do it?

这可以使用jQuery吗?

Is that possible to do so using jQuery?

推荐答案

几种方式



Few ways


  1. 服务器端回发

在页面上放置一个POST表单并将序列化对象保存在隐藏的输入中,然后将其发布到另一页。您将能够在服务器上处理该数据,并且很可能以某种方式将其放回到页面中。无论是javascript对象还是其他任何内容。

Have a POST form on your page and save your serialized object inside a hidden input then post it to the other page. You will be able to process that data on the server and most likely put it back somehow into the page. Either as javascript object or anything else.

客户端URL检查

通过将序列化对象附加到URL,向其他页面发出GET请求:

Make a GET request to your other page by attaching your serialized object to URL as:

http://www.app.com/otherpage.xyz?MyObject=SerializedData

其他页面可以轻松解析其URL并使用Javascript反序列化数据。

That other page can then easily parse its URL and deserialize data using Javascript.

<$ c中的内容$ c> window.name =本地跨页面会话

What's in a window.name = local cross-page session

这是一种特殊技术,也用于特殊的JavaScript库,它将 window.name 公开为字典,这样你就可以将许多不同的对象保存到其中并将其用作本地跨页面会话。它有一些可能会影响您的大小限制,但请检查链接页面并测试您的浏览器。

This is a special technique that's also used in a special javascript library that exposes window.name as a dictionary, so you can save many different objects into it and use it as local cross-page-session. It has some size limitations that may affect you, but check the linked page for that and test your browsers.

HTML5本地存储空间

HTML5具有本地存储的功能,您可以将其用于这些目的。但是使用它很大程度上取决于您的浏览器要求现代浏览器支持它,即使在重新启动浏览器或计算机后也可以恢复数据...

HTML5 has the ability of local storage that you can use exactly for these purposes. But using it heavily depends on your browser requirements. Modern browsers support it though and data can be restored even after restarting browsers or computers...

Cookies

您可以随时使用cookies,但可能会遇到限制。这些天cookie不是最佳选择,即使它们能够保存比当前窗口会话更长的数据。

You can always use cookies but you may run into their limitations. These days cookies are not the best choice even though they have the ability to preserve data even longer than current window session.



Javascript对象序列化



在某些大写情况下,您当然必须在客户端使用某种(de)序列化程序。反序列化器很容易找到(jQuery已经包含了一个很棒的函数 $。getJSON())并且很可能已经成为当前javascript库的一部分(甚至不提 eval())。

Javascript object serialization

You will of course have to use some sort of a (de)serializer on your client side in some of the upper cases. Deserializers are rather easy to find (jQuery already includes a great function $.getJSON()) and are most likely part of your current javascript library already (not to even mention eval()).

但对于JSON字符串序列化的对象,我建议json2.js库也是由 John Resig 。该库使用浏览器内实现的JSON(反)序列化功能(如果存在)或使用它自己的实现(如果它们不存在)。因此推荐。

But for object to JSON string serialization I'd recommend json2.js library that's also recommended by John Resig. This library uses in-browser implemented JSON (de)serialization features if they exist or uses it's own implementation when they don't. Hence recommendation.

这篇关于如何将javascript对象从一个页面传递给另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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