Sencha Touch 2 - 如何使用ajax / json中止存储加载

时间:2022-08-09 19:40:36

How can I abort a store load while the ajax call is still executing? I have a simple store with proxy type of 'ajax' and 'json' reader.

如何在ajax调用仍在执行时中止存储加载?我有一个代理类型为'ajax'和'json'读者的简单商店。

The documentation does not indicate any way to abort this. I have noticed that jsonp does allow aborting a load in progress. Do I have to switch to jsonp?

该文档并未指出任何中止此方法的方法。我注意到jsonp确实允许中止正在进行的加载。我必须切换到jsonp吗?

The motivation here is that I have a search bar and list object that gets populated with results. The actual search on the backend can take 5-10 seconds. So if a user starts a search then quickly wants to do another search (in case, for example, the first search was a typo), then the new search needs to abort the first search ajax call. Otherwise, I am seeing mixed results showing up in my search results.

这里的动机是我有一个搜索栏和列表对象,其中包含结果。后端的实际搜索可能需要5-10秒。因此,如果用户开始搜索然后很快想要进行另一次搜索(例如,如果第一次搜索是拼写错误),则新搜索需要中止第一次搜索ajax调用。否则,我会在搜索结果中看到混合结果。

As usual, any help is greatly appreciated!

像往常一样,非常感谢任何帮助!

Mohammad

1 个解决方案

#1


0  

The solution I have used in the past to solve this exact problem is to track each request with an incrementing counter and as requests complete I check the counter and if a request has been made with a higher counter I disregard the result.

我过去用来解决这个问题的解决方案是使用递增计数器跟踪每个请求,并且当请求完成时,我检查计数器,如果已经使用更高的计数器进行了请求,则忽略结果。

#1


0  

The solution I have used in the past to solve this exact problem is to track each request with an incrementing counter and as requests complete I check the counter and if a request has been made with a higher counter I disregard the result.

我过去用来解决这个问题的解决方案是使用递增计数器跟踪每个请求,并且当请求完成时,我检查计数器,如果已经使用更高的计数器进行了请求,则忽略结果。