Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何避免表加载过时的搜索查询_Java_Angularjs_Http_Search - Fatal编程技术网

Java 如何避免表加载过时的搜索查询

Java 如何避免表加载过时的搜索查询,java,angularjs,http,search,Java,Angularjs,Http,Search,我有一个通过REST端点执行简单搜索的webapp。每个搜索都有0个或多个参数。我如何防止这种情况 User submits search request "A" Before allowing "A" to return they modify their request and submit a new search request "B" 此时,用户希望看到“B”的结果,但根据搜索返回的顺序,可能会显示其中一个。如何防止搜索结果“A”填充表 我正在考虑从搜索词创建一个散列,将散列与搜索请

我有一个通过REST端点执行简单搜索的webapp。每个搜索都有0个或多个参数。我如何防止这种情况

User submits search request "A"
Before allowing "A" to return they modify their request and submit a new search request "B"
此时,用户希望看到“B”的结果,但根据搜索返回的顺序,可能会显示其中一个。如何防止搜索结果“A”填充表

我正在考虑从搜索词创建一个散列,将散列与搜索请求一起发送,并将返回值中的散列与最近提交的搜索条件的散列进行比较,并且仅在散列匹配时加载请求结果


如果以前有人问过这个问题,我很抱歉,但我找不到。我使用的是Angular1.4UI和Java/Spring后端。我认为这可能是已建立模式的常见问题。

您可以修饰$http并向返回的承诺添加中止方法。这将允许您在实现中检查承诺,并使用abort()取消以前的承诺请求(下面文档块中的实现示例)


演示如何调用服务以及如何处理响应。
;(function(angular, undefined) {

  angular.module('app.appConfigs')
    .config(httpDecoratorConfig);

  function httpDecoratorConfig($provide) {
    $provide.decorator('$http', decorateHttpWithAbort);
  }

  /**
   * decorate $http response promise with an abort function.
   * use this on destroy where you want to abort the outstanding request made on
   * a page before leaving the page.
   *
   * @example
      var requestPromise = $http(reqConfig).then(...).catch(...).finally(...);

      $onDestroy() {
        requestPromise.abort();
      }
   */
  function decorateHttpWithAbort(_, $q, $delegate) {
    var originalHttpService = $delegate;

    function newHttpServiceConstructor(requestConfig) {
      var canceller = $q.defer();
      var proxyRequest = $q.defer();
      var onAbortCallback = angular.noop;

      // adding abortFn into request promise
      proxyRequest.promise.abort = function abortFn() {
        canceller.resolve();
      };

      // by using onAbort capture the callback function which will be called
      // when the request is aborted, use this to perform cleanups.
      proxyRequest.promise.onAbort = function onAbortFn(callback) {
        onAbortCallback = callback;
        return this;
      };

      // adding request canceller promise in the original request config.
      requestConfig.timeout = canceller.promise;

      originalHttpService(requestConfig).then(
        function onSuccess() {
          proxyRequest.resolve.apply(this, arguments);
        },
        function onError(resp) {
          // don't resolve the abort response with error instead call provided
          // on abort callback to give user a change to handle abort case.
          // natively angular abort is resolved with error.
          if (resp.status === -1) {
            onAbortCallback();
            return;
          }

          proxyRequest.reject.apply(this, arguments);
        },
        function onNotification() {
          proxyRequest.notify.apply(this, arguments);
        }
      );

      return proxyRequest.promise;
    }

    // inherit all derived methods from original $http like $get, $put etc
    _.assign(newHttpServiceConstructor, originalHttpService);

    return newHttpServiceConstructor;
  }

})(angular);