0

I am building a webapp and have a few arrays that I would like to pass through the URL in order to make the results of my application easily sharable.

Is there an efficient way to do this? I know a lot of websites (like youtube) use some sort of encoding to make their URLs shorter, would that be an option here?

Thanks in advance!

4

1 回答 1

0

我怀疑您要问的是您有一些页面,用户可以在其中更改信息等,并且您想要一种使用该信息动态创建 URL 的方法,以便可以轻松地再次访问它。我在这里列出了两种方法:

  1. 使用查询字符串。在您的页面上,您可以有一个“保存”按钮,该按钮会生成一个 URL,其中包含有关用户所做操作的信息。例如,如果我有一个网页,我所做的只是输入我的名字并选择一种颜色,我可以将其编码为http://my-website.com/page?name=John_Doe&color=red. 然后,如果我访问该链接,您的页面可以访问 JavaScript 中的查询对象并加载已设置nameandcolor字段的页面。

  2. “YouTube 风格” URL 的一种方法是创建与页面对应的相关信息的哈希值。例如,如果我正在为用户创建一个存储纯文本文件的服务。这些文件应具有以下属性:title, date, name, and body. 我们可以创建字符串的哈希值hash_string = someHashFunction(title+date+name)

当然,这是一个非常幼稚的散列方案,但您可能正在寻找类似这样的东西。在此之后,您的 URL 将类似于http://my-website.com/hash_string. 这里的关键不仅在于创建这些 URL,还在于能够将服务器端的请求路由到与hash_string.

于 2013-07-22T18:58:15.570 回答