[英]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: 正如我在评论中所提到的,实现您想要的东西有多种方法,决定一个或另一个将高度取决于您想做的事情或方式:
You need to consider the answer to those questions before deciding from one method or another. 在决定使用一种或另一种方法之前,您需要考虑这些问题的答案。 Here are some options:
以下是一些选项:
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: 优点:
Cons: 缺点:
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. 对于您的特殊情况 :我可能不会采用这种方法,因为您要来回发送(大量)数据,这对性能(尤其是在移动连接中)不利。
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: 优点:
Cons: 缺点:
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发送到服务器。
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: 优点:
Cons: 缺点:
For your particular case : This is probably what you are doing right now, and you want to change it :) 对于您的特定情况 :这可能是您现在正在执行的操作,并且您想更改它:)
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: 优点:
Cons: 缺点:
For your particular case : I wouldn't go with this method because it is complex and not fully supported. 对于您的特殊情况 :我不会使用此方法,因为它很复杂并且不受完全支持。
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,它具有两种在用户浏览器中本地存储数据的方法: localStorage和sessionStorage 。 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: 优点:
Cons: 缺点:
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.