ded / reqwest

browser asynchronous http requests
2.94k stars 341 forks source link

Uncaught TypeError: Cannot call method 'abort' of undefined on line 218 #73

Open troynt opened 12 years ago

troynt commented 12 years ago

line 218 Uncaught TypeError: Cannot call method 'abort' of undefined

The requests are going through as expected, but I get that error message.

I'll probably just add a typeof check there, but I wanted to bring it to your attention.

My AJAX request looks like the following:

var xhr = reqwest({
    url: url,
    data: options,
    dataType: 'jsonp',
    type: 'jsonp',
    timeout: this.opts.timeout,
    crossDomain: true,
    success: function(resp) {
      callback.success(resp);
    },
    error: function(resp) {
      if (error_timeout) {
        clearTimeout(error_timeout);
      }
      callback.error(resp);
    }
  });

Thanks,

Troy

troynt commented 12 years ago

The following gets rid of the error:

Reqwest.prototype = {
  abort: function () {
    if( typeof this.request !== 'undefined' && typeof this.request.abort === 'function' ) {
      this.request.abort();
    }
  }
...
ded commented 12 years ago

hmm... could be that you have that combo of jsonp and crossDomain both set. remove the crossDomain and see if it still throws the error

ded commented 12 years ago

but yeah, you're right on that... jsonp requests aren't XHR objects, which of course don't have abort methods... so yeah we'll have to fix that

shellscape commented 9 years ago

@ded issue is an old one and running into this on IE8,9.