使用ajax的Jquery管理表和追加\删除行的最佳方法是什么

时间:2022-09-16 14:30:54

I am very new to jquery and Ajax. I'm working with an ActiveX control that draws little sketch documents. When users save a new sketch using this control I send the data back to the server using Ajax. One of my requirements it to show a list of thumbnails in the page of existing sketches. For this list I've deiced to simply use a table, however the problem is what would be the very best way to manage this table using AJax?

我是jquery和Ajax的新手。我正在使用一个ActiveX控件来绘制一些草图文档。当用户使用此控件保存新草图时,我使用Ajax将数据发送回服务器。我要求它在现有草图的页面中显示缩略图列表。对于这个列表,我只是想使用一个表,但问题是使用AJax管理这个表的最佳方法是什么?

I can think of several way to do this:

我可以想到几种方法来做到这一点:

  1. Have the Ajax request respond with an entire new table with all of the sketch thumb nail links,
  2. 让Ajax请求响应一个包含所有草图缩略图链接的整个新表,
  3. or I could respond with all of the rows.
  4. 或者我可以回复所有行。
  5. Another possibility I can think of is to not respond with html at all but with JSon data that has all of the information I need to build the table and then use Jquery to build the table and append new rows or delete new rows as the users create and delete sketches.
  6. 我能想到的另一种可能性是根本不用html响应,而是使用JSon数据,它拥有构建表所需的所有信息,然后使用Jquery构建表并在用户创建时追加新行或删除新行并删除草图。
  7. Something else.
  8. 还有别的。

What approach would you use?

你会用什么方法?

1 个解决方案

#1


0  

The important question is this: "Where should the 'visual display' part of your code live? Mostly on the server, or mostly on the javascript client?"

重要的问题是:“代码的'视觉显示'部分应该在哪里?主要是在服务器上,或者主要在javascript客户端上?”

Myself, I would send JSON back to the client (#3) and then have the client be responsible for putting the images into a table, using one of a variety of Javascript templating systems, like EJS. This way the server-side doesn't have to care about how things look, it just has a fairly basic responsibility to organize data and objects.

我自己,我会将JSON发送回客户端(#3)然后让客户端负责将图像放入表中,使用各种Javascript模板系统之一,如EJS。这样,服务器端就不必关心事物的外观,它只是负责组织数据和对象。

#1


0  

The important question is this: "Where should the 'visual display' part of your code live? Mostly on the server, or mostly on the javascript client?"

重要的问题是:“代码的'视觉显示'部分应该在哪里?主要是在服务器上,或者主要在javascript客户端上?”

Myself, I would send JSON back to the client (#3) and then have the client be responsible for putting the images into a table, using one of a variety of Javascript templating systems, like EJS. This way the server-side doesn't have to care about how things look, it just has a fairly basic responsibility to organize data and objects.

我自己,我会将JSON发送回客户端(#3)然后让客户端负责将图像放入表中,使用各种Javascript模板系统之一,如EJS。这样,服务器端就不必关心事物的外观,它只是负责组织数据和对象。