简体   繁体   English

在html页面之间共享Json

[英]Share Json between html pages

I have used jQuery AJAX got a string of JSON in the login page. 我已经使用jQuery AJAX在登录页面中获取了JSON字符串。 How can I use it in other pages. 我如何在其他页面中使用它。 Are there some method to store the JSON and access it anywhere in my website. 有什么方法可以存储JSON并在我的网站中的任何地方访问它。 ps. ps。 I didn't use any other server script, it is only a html website. 我没有使用任何其他服务器脚本,它只是一个html网站。 The JSON string is about 5K byte. JSON字符串约为5K字节。

You can use localStorage . 您可以使用localStorage

// Store
localStorage.setItem("json", JSON.stringify(json));
// Retrieve
JSON.parse(localStorage.getItem("json"));

You can use localStorage or cookie to store your json . 您可以使用localStoragecookie存储您的json

Read about Web-storages 了解有关Web存储的信息

But remember cookie has size limitations, read this . 但是请记住cookie有大小限制,请阅读此内容

您可以将json存储在.json文件中,请求可以转到这些文件并使用JSON.parse解析响应JSON.parse

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 html 页面之间共享变量 - Share variables between html pages 在html页面之间共享数据 - Share data between html pages 如何在页面之间共享 HTML 元素及其类? - How to share HTML elements and their classes between pages? 应该使用什么来在 HTML 和 PHP 中的页面之间共享变量? - What should be use to share variables between pages in HTML and PHP? AngularJS:在页面之间共享数据 - Angularjs: share data between pages EJS在2页之间共享数据 - EJS share data between 2 pages 如何在不使用window对象的情况下在jquery移动页面之间共享json数据 - How to share json data between jquery mobile pages with out using window object 是否可以使用HTML5本地存储在不同站点的页面之间共享数据? - Is it possible to use HTML5 local storage to share data between pages from different sites? 如何使用单个Javascript文件在两个或更多HTML页面之间共享本地存储,而不会出现“空”的情况? - How to share local storage between two or more HTML pages using a single Javascript file and not getting “null”? 我可以在HTML页面上的表单之间共享数据吗? 还是可以提交一种形式,提交另一种形式? - Can I share data between forms on HTML pages? Or can submitting one form, submit another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM