是否有可能取消微风请求(AngularJS)?有可能、微风、AngularJS

2023-09-10 20:33:17 作者:今夜酷暑不宜裸奔

我试图找到一种方法来取消BreezeJS查询实现实时搜索,查询BreezeJS关键preSS的目的(见我的其他问题)。

I'm trying to find a way to cancel BreezeJS queries for the purpose of implementing a live search that queries BreezeJS on keypress (see my other question).

我知道,在棱角分明, $ HTTP 请求可以通过传递一个承诺到暂停参数取消在配置对象,然后调用解析()这一承诺。

I know that in Angular, $http requests can be cancelled by passing a promise to the timeout parameter in the config object, and then calling resolve() on that promise.

我也知道,我能得到BreezeJS用我的模块的 $ HTTP insance有:

I also know that I can get BreezeJS to use my module's $http insance with:

var ajax = breeze.config.initializeAdapterInstance('ajax', 'angular');
ajax.setHttp($http);

所以我在想可能是创建一个要求拦截器在 $ HTTP 将设置 config.timeout 来一个承诺。但是,这仍然让我相当几步之遥解决这个问题,因为我会以某种方式需要能够从code运行查询(给的承诺我的拦截器,以使查询code能如果需要解析()的承诺)。

So I was thinking about possibly creating a request interceptor on $http that would set config.timeout to a promise. But that still leaves me quite a few steps away from solving the problem, because I would somehow need to be able to give the promise to my interceptor from the code running the query (so that the querying code could resolve() the promise if needed).

有没有更好的办法?它甚至有可能?

Is there a better way? Is it even possible?

推荐答案

您可以使用AJAX适配器的 requestInterceptor 设置HTTP级别的超时和取消的v.1.4.12的。查看文档,控制AJAX调用。

Update 16 May 2014

You can set HTTP-level timeout and cancellation with the AJAX Adapter's requestInterceptor as of v.1.4.12. See the documentation, "Controlling AJAX calls".

在的EntityManager HTTP服务业务不提供取消或超时选项。也许他们有一天会。

The EntityManager HTTP service operations don't offer cancel or timeout options. Maybe they will someday.

在v.1.4.11微风 AJAX适配器不提供取消或超时选项要么。 但他们会在v.1.4.12 的,你可以看到在github上的preVIEW现在。

The v.1.4.11 Breeze AJAX adapters don't offer cancel or timeout options either. But they will in v.1.4.12 and you can see the preview on github right now.

在GitHub上的示例说明这两种新的适配器取消和超时。对于jQuery的AJAX组件的用户有 文档code :jQueryAjaxAdapterTests.js 的。对于用户角的 $ HTTP 还有就是 ZZA节点 - 蒙戈:AJAX-adapter.async.spec.js 的

The samples on github illustrate both cancel and timeout with the new adapters. For users of the jQuery AJAX component there is DocCode:jQueryAjaxAdapterTests.js. For users of Angular's $http there is the Zza-Node-Mongo:ajax-adapter.async.spec.js.

这是最好的,如果你可以运行样品,但如果你不能(也许是因为你不使用所涉及的技术之一),测试文件(见上面的链接)易于阅读,你应该搜集的想法这将有助于。至少我希望如此。

It's best if you can run the samples but if you can't (perhaps because you don't use one of the technologies involved), the test files (see links above) are easy to read and you should glean the ideas that will help. At least I hope so.

取消和超时非常有用的功能。你需要他们为你的使用情况?有可能。但是你要采取的第一个步骤去弹跳用户进入你的生活搜索的文字,让你不会发射了毫无意义的查询100秒。

Cancel and timeout are useful features. Do you need them for your use case? Maybe. But you'd want to take a first step of de-bouncing the text that users enter into your "live search" so that you aren't firing off 100s of pointless queries.

这个意见在your相关的StackOverflow问题。

 
精彩推荐
图片推荐