Skip to content
This repository has been 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 opened this issue Nov 12, 2013 · 2 comments
Closed

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

burib opened this issue Nov 12, 2013 · 2 comments

Comments

@burib
Copy link

burib commented Nov 12, 2013

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'));
});
@filipefmelo
Copy link

Yup, I've got the same problem.

gonzaloruizdevilla pushed a commit to gonzaloruizdevilla/angular.js that referenced this issue Nov 13, 2013
When a request is aborted, it makes no sense to read the response headers or text.
Also in IE9, trying to read data (either response headers or text) from an aborted request
throws an Error c00c023f.

Fixes angular#4913
@burib
Copy link
Author

burib commented Nov 20, 2013

tested it in IE9, looking good.

jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
When a request is aborted, it makes no sense to read the response headers or text.
Also in IE9, trying to read data (either response headers or text) from an aborted request
throws an Error c00c023f.

Fixes angular#4913
Closes angular#4940
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
When a request is aborted, it makes no sense to read the response headers or text.
Also in IE9, trying to read data (either response headers or text) from an aborted request
throws an Error c00c023f.

Fixes angular#4913
Closes angular#4940
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants