Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

aborting xhr request results in console.error in IE9 #4913

Closed
@burib

Description

@burib

when cancelling an xhr request, IE9 throws error in console ( Could not complete the operation due to error c00c023f. ) and error callback of the promise doesn't get called.

App

<div ng-app="queryApp" ng-controller="QueryCtrl">
  <input type="button" ng-click="send()" value="SendQuery"><br/>
  <input type="button" ng-click="cancel()" value="CancelQuery"/>

  <p>status: {{status}}</p>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js"></script>
<script>
  angular.module('queryApp', []).

      service('QueryService',function ($http, $q, $timeout) {
        var deferred = null,
            timer = null;

        return {
          cancelQuery: function () {
            deferred.resolve();
          },
          sendQuery: function (query) {
            /**
             * cancel previous request if there was any.
             */
            if(deferred) {
              this.cancelQuery();
            }
            deferred = $q.defer();
            this.startTimeout();
            return $http.
                get('/data', {
                  timeout: deferred.promise
                }).
                then(function (response) {
                  return response.data;
                });
          },

          startTimeout: function () {
            this.stopTimeout();
            var self = this;
            timer = $timeout(function () {
              self.cancelQuery();
            }, 3000);
          },

          stopTimeout: function () {
            if(timer) {
              $timeout.cancel(timer);
            }
          }
        }
      }).

      controller('QueryCtrl', function ($scope, QueryService) {
        $scope.status = 'init';

        $scope.cancel = function () {
          $scope.status = 'canceled';
          QueryService.cancelQuery();
        };
        $scope.send = function () {
          $scope.status = 'loading...';
          QueryService.sendQuery().then(function () {
                $scope.status = 'done!';
              },
              function () {
                /**
                 * IE doesn't run into this block.
                 */
                $scope.status = 'timeout';
              });
        };
      });
</script>

Server

var express = require('express'),
    http = require('http'),
    app = express();

app.set('port', process.env.PORT || 666);
app.use(express.static(__dirname + '/public', { maxAge: 666 }));

app.get('/data', function (req,res) {
    res.type('application/json');
    setTimeout(function () {
        res.send({});
    }, 6000);
});

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions