在不刷新的情况下更新站点(大量数据)的最有效方法?

发布于 2024-08-05 08:40:42 字数 543 浏览 9 评论 0原文

我正在开发一个网络项目,该项目需要多个用户和大量数据进行大量更新。

预期数据量为 70 个唯一行,每行有 14 个需要定期更新的字段。总共有 980 个字段。

我首先尝试使用 for 循环对数据库进行一系列同步 ajax 查询来更新所有字段。这导致了严重的挂起。我想说的是,在 30 秒的更新间隔中,有 20 秒页面被冻结了。

下一次尝试是异步运行 ajax 查询,并在 for 循环中成功更新字段。这缓解了速度减慢的情况,但我遇到了奇怪的问题。我认为我的 for 循环变量更改导致内容被写入错误的 HTML 元素。

目前我有一个后端.asp页面编写HTML,并清除包含div的innerHTML,然后设置div.innerHTML = Transport.responseText。这对我来说似乎工作得很好,但我只是好奇在有可用工具(vbscript、javascript 和 Access 数据库)的情况下,其他人会做什么来更新这么多数据。

所有工作站的数据都是相同的,多个用户将实时交互编辑数据。然而,他们每个人都会关心更新自己的数据部分,但需要让所有用户在最新的迭代中都可更新和查看。

I am working on a web project that will require quite a bit of updating from multiple users and large ammounts of data.

The expected ammount of data is 70 unique rows each with 14 fields that need updated regularly. That's a total of 980 fields.

I first attempted a series of synchronous ajax queries to the database using a for loop to update all the fields. This caused a large hang. I would say for 20 seconds of my 30 second time between updates the page was frozen.

The next attempt was to run the ajax queries asynchronously with onsuccess updating the fields in a for loop. This aleviated the slow down, but I was getting weird issues. I think my for loop variable changing was causing things to be getting written to the wrong HTML elements.

Currently I am having a back end .asp page write the HTML, and clearing the innerHTML of the containing div, then setting div.innerHTML = transport.responseText. This seems to be working pretty well for me, but I am just curious as to what others would have done to update this much data given the tools available (vbscript, javascript, and an Access database).

The data across all work stations will be the same, and multiple users will be interacting in real time editing the data. However, they will each be concerned with updating their own portion of the data, but there is a need to have it all be updatable and viewable in its latest iteration by all users.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不忘初心 2024-08-12 08:40:42

具有 1000 个字段的 HTML 表格并不是“大量数据”。

如果您为每个单元格提供一个 ID,并使用 JSON 或简单的 CSV 获取数据,然后使用 javascript 更新所有数据,速度会更快,因为浏览器不需要重新绘制表格并创建新的 DOM 结构。

例如:

假设服务器以这种方式向您提供数据:
12,234,564,423,1223,2413,133,113,5443...

然后在javascript中你可以这样:

var data = responseText.split(',');

然后填充表格(假设表格单元格的id名称如CELL_0、CELL_1、CELL_2...)。

for (i=0; i<data.length; i++) {
  document.getElementById('CELL_'+i).innerHTML=data[i];
}

就是这样。

An HTML table with 1000 fields isn't a "large amount of data".

If you give an ID to each cell and get the data using JSON or simple CSV and then update all with javascript it would be faster because the browser doesn't needs to redraw the table and make new DOM structures.

por example:

Imagine that the server gives you the data this way:
12,234,564,423,1223,2413,133,113,5443...

then in javascript you can make:

var data = responseText.split(',');

and then fill the table (suppose that the table cells have id names like CELL_0, CELL_1, CELL_2...).

for (i=0; i<data.length; i++) {
  document.getElementById('CELL_'+i).innerHTML=data[i];
}

that's it.

风苍溪 2024-08-12 08:40:42

用户期望如何与页面交互?多个用户是否会同时处理相同的数据?他们是否希望看到彼此的结果?您标记了这个 asp.net,但提到只能使用 vbscript、javascript 和访问 - 这个 asp.net 怎么样?

编辑:

感谢您的澄清。每行都有一个编辑/保存按钮会有帮助吗?这些行将是只读的,直到用户需要编辑其数据(我假设他们正在编辑每一行),数据将刷新并且该行将被锁定以供任何其他用户编辑。当用户完成后,他们单击“保存”,他们的数据将被更新,该行将被解锁,并且页面的数据将被刷新。您还可以将 ajax 设置为每隔几分钟运行一次,以便在用户未主动编辑时获取最新信息。另外 - 根据您的数据的结构 - 您应该只需要获取自用户页面上次更新以来已更改的数据。不需要每次都得到一切。您的更新也应该很小,仅限于他们正在编辑的用户行上的数据。

How are the users expected to interact with the page? Will multiple users be working on the same data at the same time and are they expected to see each others results? You tagged this asp.net but mention only being able to use vbscript, javascript and access - how is this asp.net?

Edit:

Thanks for the clarifications. Would having an edit/save button on each row help? The rows would be read only until the user needs to edit their data (I'm assuming they're editing each row) the data would refresh and the row would be locked for editing by any another user. When the user is done they click save and their data is updated, the row is unlocked, and the page's data is refreshed. You could additionally have the ajax set to run every few minutes to get the latest when the user is not actively editing. Also - depending on how your data is structured - you should only need to get data that has been changed since the user's page was last updated. No need to get everything every time. Your update should also be small, limited to just the data on the user's row that they're editing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文