简体   繁体   English

可以对多个HTML页面使用jQuery JSON吗?

[英]Possible to Use jQuery JSON For Multiple HTML Pages?

I have an HTML page where the user fills in a few forms for their own reference (purely client-side, it doesn't get submitted to server). 我有一个HTML页面,用户可以在其中填写一些表格以供自己参考(纯客户端,不会提交给服务器)。 I'd like to be able to store that submitted text on the user's computer, and then reproduce that text on another HTML page when the user visits the other page. 我希望能够将提交的文本存储在用户的计算机上,然后在用户访问另一个页面时在另一个HTML页面上重现该文本。

Is this possible to do using jQuery JSON? 使用jQuery JSON可以做到吗? Perhaps with .getJSON and/or .parseJSON? 也许使用.getJSON和/或.parseJSON? (If so, I would guess that both HTML pages need to refer to the same .JS file.) (如果是这样,我猜这两个HTML页面都需要引用相同的.JS文件。)

Or would this be more of a cookie thing? 还是更多的是cookie?

Also, if this is possible, I would love a link to an article about how to do this - if one exists. 另外,如果可能的话,我希望链接到一篇有关如何执行此操作的文章-如果存在的话。

Thanks so much for your help. 非常感谢你的帮助。

I don't know what sort of browser support you need, but eligrey/FileSaver.js will save your file, but javascript can't automatically read content from a user's computer without their input - this is a tutorial on reading files submitted by the user . 我不知道您需要哪种浏览器支持,但是eligrey / FileSaver.js会保存您的文件,但是javascript无法在没有用户输入的情况下自动从用户计算机中读取内容- 这是有关如何读取用户提交的文件的教程用户

If you want this to be seamless, you want to use cookies or local storage . 如果您希望这是无缝的,则要使用Cookie本地存储

As all variables are lost when the javascript is reloaded (which happens when the user loads another HTML which references the same .js), you could store the values in a browser Cookie. 由于在重新加载javascript时所有变量都会丢失(在用户加载引用相同.js的另一个HTML时发生),因此您可以将值存储在浏览器Cookie中。

You can serialize the data as JSON in the cookie if you'd like, this is entirely up to you. 您可以根据需要在Cookie中将数据序列化为JSON,这完全取决于您。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM