在做AJAX编辑到数据库中,我应该立即用​​新的数据更新接口数据库中、接口、编辑、立即用

2023-09-11 01:01:27 作者:拔刀总裁

我使用的是内联编辑,更新与AJAX数据库中的文本。这是基本的过程中,pretty的平常的东西:

I'm using inline-edit to update text in the database with AJAX. This is basically the process, pretty usual stuff:

在文本是不可编辑 我点击的文本,就变成可编辑 我键入新的文本 然后单击发送更新文本到数据库 然后返回文本不可编辑的格式为:

我的问题是我应该更新时,用新的数据接口?我应该Ajax调用之前立即进行更新,或者我应该等待更新响应返回数据库?

My question is when should I update the interface with the new data? Should I update it immediately before the ajax call, or should I wait for the update response to return from the database?

我关心的:

如果我不马上更新界面,并迫不及待地想从数据库的响应,那么我已经失去了自带的AJAX异步的好处。 但是,如果我马上更新,那么如果数据库响应有错误,我不知要跟踪我已经进行了更改,并扭转这种局面,这是一个很大的工作。

那么,如何在这样的事情通常是?

So how is this sort of thing usually done?

推荐答案

我觉得这是完全合理的等待响应和更新作为回调的结果。这样做不会从异步方法得出。它仍然是完全异步,因为你没有阻止整个页面或完全重装了。

I think it is completely reasonable to wait for the response and update as a result of a callback. Doing so does not detract from the async approach. It is still fully async because you are not blocking the entire page or reloading it completely.

大量的次应用,尤其是在移动的人,其中的带宽可能是有限的,我会看到一个微调指示该字段被提交。这不托起应用程序的其他部分。即使计算器做到这一点,当我用手机查看。依靠回调,以保持异步,但仍然可以同步到数据库返回值。

Plenty of times in apps, especially in mobile ones where the bandwidth might be limited, I will see a spinner indicating that the field is submitting. This does not hold up any other part of the app. Even stackoverflow does this when I use the mobile view. Rely on the callbacks in order to stay async and still be synced to database return values.