在数据库中添加数据后,通过AJAX添加/删除表行的最佳方法是什么

时间:2022-09-17 11:02:47

Quite often i need to add/delete/update the item in database via Jquery POST. Now the next step is to either dynamically add row again via AJAX to show that this row was added or remove the row if it was deleted.

我经常需要通过Jquery POST添加/删除/更新数据库中的项目。现在,下一步是通过AJAX再次动态添加行以显示已添加此行或删除该行(如果已删除)。

I want to know which method is best and used by companies.

我想知道哪种方法最适合公司使用。

The other solution i think is to update the whole List with jquery so that i don't need to program separate function for edit/add/delete

我认为另一个解决方案是使用jquery更新整个List,这样我就不需要为编辑/添加/删除编写单独的函数

So how should i go

那我该怎么办呢

1 个解决方案

#1


0  

Reloading whole list is very inefficient. It slows user too. Server can respond informatically about the database action. So if the operation succeeds, server can respond for example:

重新加载整个列表效率非常低。它也减慢了用户的速度。服务器可以有信息地响应数据库操作。因此,如果操作成功,服务器可以响应,例如:

{'response': 'OK'}

and if operation fails, server can respond something like:

如果操作失败,服务器可以响应如下:

{'response': 'FAILED', 'message': 'Problems with database connection'}

You can then update the affected list row, depending on the response, in the ajax callback function.

然后,您可以在ajax回调函数中更新受影响的列表行,具体取决于响应。

#1


0  

Reloading whole list is very inefficient. It slows user too. Server can respond informatically about the database action. So if the operation succeeds, server can respond for example:

重新加载整个列表效率非常低。它也减慢了用户的速度。服务器可以有信息地响应数据库操作。因此,如果操作成功,服务器可以响应,例如:

{'response': 'OK'}

and if operation fails, server can respond something like:

如果操作失败,服务器可以响应如下:

{'response': 'FAILED', 'message': 'Problems with database connection'}

You can then update the affected list row, depending on the response, in the ajax callback function.

然后,您可以在ajax回调函数中更新受影响的列表行,具体取决于响应。