简体   繁体   English

如何将数据从一页传递到另一页?

[英]How can I pass data from one page to another?

So regarding my question I have two pages.所以关于我的问题,我有两页。 Page1.php to save customer sale information and Page2.php to display the sales(Page2 is connected to a monitor in our office no user interaction, no keyboard, no mouse). Page1.php保存客户销售信息, Page2.php显示销售情况(Page2 连接到我们办公室的显示器,没有用户交互,没有键盘,没有鼠标)。

. .

In Page1 the users can save information about customer sales.在 Page1 中,用户可以保存有关客户销售的信息。 For example product name.例如产品名称。 The users user is always connected to the sale.用户用户始终连接到销售。 After submitting the sale, I want it to show up on Page2., and says something like: User Demitri just sold a PS4 .提交销售后,我希望它显示在 Page2. 上,并说如下: User Demitri just sell a PS4

What have I tried so far :到目前为止我尝试了什么

Now when the user register sale, it saves into a MySQL table, and the Page2.现在当用户注册销售时,它保存到一个 MySQL 表中,以及 Page2。 automatically refreshes( <meta http-equiv="refresh" content="10"/> ) the page every 10 second to see if any new record has been added to the table.每 10 秒自动刷新( <meta http-equiv="refresh" content="10"/> )页面以查看是否有任何新记录添加到表中。 If a new record is there, it will display the user and the product that was sold on the page for 30 seconds, example: User Demitri just sold a PS4 , and then it will remove the record from the table, and then refresh the page again to see if any new record has been added to the table.如果有新记录,它会在页面上显示用户和售出的产品30秒,例如: User Demitri just sell a PS4 ,然后将记录从表中删除,然后刷新页面再次查看是否有任何新记录添加到表中。

What do I want to accomplish:我想完成什么:

I want a sort of system that can be used to pass data from Page1.我想要一种可用于从 Page1 传递数据的系统。 to Page2, without needed any user interaction on Page2, and don't need to have a auto refresh script that runs every 10 second.到 Page2,无需在 Page2 上进行任何用户交互,也不需要每 10 秒运行一次的自动刷新脚本。 This also looks bad because every time it refreshes, the website will sort of blink.这看起来也很糟糕,因为每次刷新时,网站都会闪烁。

This is a very cumbersome process to do it, there must be some other way?这是一个非常繁琐的过程,一定有其他方法吗?

我会推荐使用 dB 来存储数据,需要该数据的页面可以查询数据.. 也许使用 ajax、fetch 和一些 setinterval 函数

  1. Use ajax, so you don't have to refresh the page every 10 seconds.使用ajax,这样你就不必每10秒刷新一次页面。
  2. Use websockets.使用网络套接字。 Once you notice a new sale, you just push it and then your connected page can display it.一旦你注意到一个新的销售,你只需推送它,然后你的连接页面就可以显示它。 This would be the best way i think.这将是我认为最好的方式。

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

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