简体   繁体   English

我有大量来自服务器的行数据。 如何在新页面(即重定向页面)上显示此数据?

[英]I have a large number of row data coming in from server. How do I display this data on a new page(i.e Redirected Page)?

On Page 1, I have a large number of row data(JSON) coming in from server in an array. 在第1页上,我从数组中的服务器传入了大量行数据(JSON)。 I want to display this data on Page 2 which is the page to be redirected to on clicking a Page 1. I am using Javascript/Jquery and PHP code on server. 我想在页面2上显示此数据,这是单击页面1时将重定向到的页面。我在服务器上使用Javascript / Jquery和PHP代码。

I read elsewhere that this can be done using forms, but how do I assign values to to the fields? 我在其他地方读到,可以使用表单来完成此操作,但是如何将值分配给字段? Can someone show how exactly this is done? 有人可以证明这是如何完成的吗?

As I mentioned in the comments, there are multiple ways of achieving what you want, deciding on one or another will highly depend on how or what you want to do: 正如我在评论中所提到的,实现您想要的东西有多种方法,决定一个或另一个将高度取决于您想做的事情或方式:

  • Is it a large amount of data? 数据量大吗?
  • Do you want it to be done in client or server side? 您要在客户端还是服务器端完成?
  • Do you have any security concerns? 您是否有安全方面的顾虑?
  • Are there any bandwidth limitations? 有带宽限制吗?
  • etc. 等等

You need to consider the answer to those questions before deciding from one method or another. 在决定使用一种或另一种方法之前,您需要考虑这些问题的答案。 Here are some options: 以下是一些选项:


Forms 形式

You could put the data in a form on page 1 (either formatted or just as one big chunk that will be reprocessed on page 2), and submit the data from one to the other. 您可以将数据放在第1页上的form (格式化或作为一个大块,将在第2页上重新处理),然后将数据从一个提交到另一个。

<form method="POST" action="page2.php">
    <textarea name="data">YOUR DATA HERE</textarea>
</form>

If you already have a form to send data from page 1 to page 2, then consider adding it as a hidden input that you can read on page 2. 如果您已经有了将数据从第1页发送到第2页的表单,请考虑将其添加为隐藏输入,以便在第2页上阅读。

Pros: 优点:

  • Easy to implement. 易于实现。
  • Various possibilities (GET or POST, all in one field or each element in a field) 多种可能性(GET或POST,全部在一个字段中或字段中的每个元素)
  • More flexible if you allow user to make changes to the data. 如果允许用户更改数据,则更加灵活。

Cons: 缺点:

  • Heavy traffic load. 交通繁忙。 The same data would travel multiple times: server > client (when loading page 1), client > server (submitting form), server > client (loading page 2). 相同的数据将多次传输:服务器>客户端(在加载第1页时),客户端>服务器(提交表单),服务器>客户端(在加载第2页时)。
  • Limited size if you use the GET method: you'd be restricted in size limit by server and client (browser). 如果使用GET方法,则限制大小:服务器和客户端(浏览器)将限制大小。

For your particular case : I probably wouldn't go for this method as you would be sending (a large amount of) data back and forth, and that is not good for performance, specially in mobile connections. 对于您的特殊情况 :我可能不会采用这种方法,因为您要来回发送(大量)数据,这对性能(尤其是在移动连接中)不利。


Cookies 饼干

You could store the data in a cookie on page 1, then read that cookie on page 2. And you could implement it in JavaScript (client side) or PHP (server side) and the result would be equivalent. 您可以将数据存储在第1页的cookie中,然后在第2页上读取该cookie。您可以在JavaScript(客户端)或PHP(服务器端)中实现它,结果将是相同的。

<?php
    $cookie_name = "data";
    $cookie_value = "YOUR DATA HERE";
    setcookie($cookie_name, $cookie_value, time() + (3600 * 24), "/"); 
?>

Pros: 优点:

  • Easy to implement. 易于实现。
  • PHP or JavaScript, the result will be similar (unless you use some HTTPOnly cookies) PHP或JavaScript,结果将是相似的(除非您使用一些HTTPOnly cookie)

Cons: 缺点:

  • Limited size. 尺寸有限。 Again it will depend on the browser that the client is using ( You can see some data on this web site ). 同样,这将取决于客户端使用的浏览器( 您可以在此网站上看到一些数据 )。
  • Not as secure as other methods (you cannot really trust what you are reading). 不如其他方法安全(您不能真正相信自己正在阅读的内容)。
  • User may have disabled/rejected cookies (you don't know if the cookie will be there). 用户可能已禁用/拒绝cookie(您不知道cookie是否在那里)。

For your particular case : I wouldn't go for this method either. 对于您的特殊情况 :我也不会采用这种方法。 It is less safe and cookies are sent to the server with each page load anyway. 它的安全性较低,并且无论如何都会在每次加载页面时将cookie发送到服务器。


Server Database / Files 服务器数据库/文件

Store the data in a database before sending it to page 1 (if you already have it on a database and don't want to rerun the query because it takes a long time, you could create a cached version of the result), then read that record on page 2. 在将数据发送到页面1之前,将其存储在数据库中(如果您已经将其存储在数据库中,并且由于花费很长时间而不想重新运行查询,则可以创建结果的缓存版本),然后读取该记录在第2页上。

Alternatively, you could follow a similar approach but instead of storing the data on a table, save the results on a file. 或者,您可以采用类似的方法,但不要将数据存储在表中,而是将结果保存在文件中。 Then page 2 would read that file and get the data. 然后,第2页将读取该文件并获取数据。

Pros: 优点:

  • You always have control over the data. 您始终可以控制数据。
  • No need to worry if user has JavaScript/cookies activated. 如果用户已激活JavaScript / cookie,则无需担心。

Cons: 缺点:

  • Complex implementation (requires permissions / redesign of solution). 复杂的实现(需要许可/解决方案的重新设计)。
  • Data will still travel twice (server > page1, and server > page2). 数据仍将传输两次(服务器>页面1,以及服务器>页面2)。

For your particular case : This is probably what you are doing right now, and you want to change it :) 对于您的特定情况 :这可能是您现在正在执行的操作,并且您想更改它:)


IndexedDB 索引数据库

Another HTML5 feature that will allow you to create a local object-oriented database , where you can store and retrieve objects using a key index. 另一个HTML5功能将允许您创建本地的面向对象的数据库 ,您可以在其中使用键索引存储和检索对象。

Pros: 优点:

  • Good performance. 很好的表现。
  • Good for large amounts of data. 适用于大量数据。
  • Data is stored locally, it does not travel to the server. 数据存储在本地,不会传输到服务器。

Cons: 缺点:

For your particular case : I wouldn't go with this method because it is complex and not fully supported. 对于您的特殊情况 :我不会使用此方法,因为它很复杂并且不受完全支持。


LocalStorage / SessionStorage LocalStorage / SessionStorage

HTML5 introduced the Web Storage API with two methods to store data locally within the user's browser: localStorage and sessionStorage . HTML5引入了Web Storage API,它具有两种在用户浏览器中本地存储数据的方法: localStoragesessionStorage The difference between the two is that with one the data will persist even when the browser is closed (localStorage), while with the other the data will only live while the page session is active (sessionStorage) 两者之间的区别在于,即使关闭了浏览器(localStorage),其中一种数据仍将保留,而另一种则仅在页面会话处于活动状态(sessionStorage)时,数据仍将保留

<script type="text/javascript">
    localStorage.setItem("data", "YOUR DATA HERE");
</script>

Pros: 优点:

  • Easy to implement. 易于实现。
  • It allows larger amounts of data than cookies (at least 5MB). 它允许的数据量大于cookie(至少5MB)。
  • Data is stored locally, it does not travel to the server. 数据存储在本地,不会传输到服务器。

Cons: 缺点:

  • Disabling cookies will disable LocalStorage too. 禁用cookie也会禁用LocalStorage。
  • LocalStorge values on secure pages are isolated (which can lead to interesting errors if your page changes between http and https). 安全页面上的LocalStorge值是隔离的(如果页面在http和https之间切换,则可能导致有趣的错误)。

For your particular case : This is the method I would go with, as long as the size of your data fits within the limits. 对于您的特殊情况 :只要您的数据大小在限制范围内,这就是我要使用的方法。

you are getting data in an array on page 1. you will have to pass this data on page 2 to display results there. 您将在第1页上的数组中获取数据,则必须在第2页上传递此数据才能在那里显示结果。 For passing the data to page 2, following steps should be performed. 要将数据传递到第2页,应执行以下步骤。
1. get json array and serialize it. 1.获取json数组并序列化。 {best alternative is get the parameters you are using to get json data. {最佳选择是获取用于获取json数据的参数。 pass those parameters to page 2 and use them to get json data. 将这些参数传递给第2页,并使用它们获取json数据。 so instead of passing array of json data pass parameters by which you can generate json data again from page 2.} 因此,您无需传递json数据数组的传递参数,而是可以通过这些参数从页面2再次生成json数据。
2. To pass the parameters/json data serialized one whichever you prefer, hide the data in dom. 2.要传递序列化的参数/ json数据中的任何一个,请将其隐藏在dom中。 the hidden data will be inside form. 隐藏的数据将在表单内部。

<form action='.page2' method='POST' id='redirect_form'>
  <hidden data in dom >
 <button type='submit' which on click redirects to page 2>
</form>


3. on page 2, make use of the data you have posted to show array. 3.在第2页上,利用您发布的数据来显示数组。

暂无
暂无

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

相关问题 如何在新页面上打开数据? - How do I open data on a new page? 如何显示一页到另一页的数据? - How do i display a data from one page to another? 我想显示一个“加载”微调器,直到数据完全从服务器加载。 如何在 javascript 中为 salesforce lwc 执行此操作? - I want to display a 'loading' spinner until data is loaded completely from the server. How to do this in javascript for salesforce lwc? 如何将json对象从jsp页面的jsp部分传递到javascript部分,即从服务器端到客户端? - How to pass a json object from the jsp part of a jsp page to the javascript part i.e from server side to client side? 我想刷新我的 html 页面上可用的所有 div,即按标签,我有 2 个代码如何 imerge - i want to refresh my all div available on my html page i.e by tag and i have 2 codes how can imerge 如何从单独的页面显示DataTable中的行数? - How do I display the number of rows in a DataTable from a separate page? 我如何从一个页面到另一个页面获取数据,只需使用JavaScript在屏幕上简单显示 - How do i get data from a page to other page,just simply display on screen with javascript 如何操作位于 state 中的数据并显示到页面? - How do I manipulate data that is located in state and display to page? 如果我们有极长的水平滚动页面,如何在最后一个元素的末尾添加边距/填充,即空间? - How to add margin/padding i.e space right to the end of the last element if we have extremely long horizontal scrolling page? 如何将大数据发布到服务器? - How do I post large data to the server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM