6

I suddenly started getting the following:

TypeError: $.ajax(...).done(...).fail(...).complete is not a function

My code:

this.sendRequest = function (type, extension, data, successCallback, successMsg, failMsg, failCallback) {

            var self = this;
            var options = {
                url: self.baseUrl + self.apiEndpoint + extension,
                type: type,
                dataType: 'json',
                xhrFields: {
                    withCredentials: true
                }
            };
            if (data != null) {
                options.data = data;
            }
            return $.ajax(options)
                .done(function (response) {
                    // do stuff
                })
                .fail(function (response) {
                    // do stuff
                }).complete(function (response) {
                    // do stuff
                });
        };

Why is this happening? I did update jQuery - did some of this syntax become invalidated?

guest271314
  • 1
  • 15
  • 104
  • 177
BLAZORLOVER
  • 1,971
  • 2
  • 17
  • 27

1 Answers1

12

.complete is deprecated....use .always

jqXHR.always(function( data|jqXHR, textStatus, jqXHR|errorThrown ) { }); (added in jQuery 1.6)

An alternative construct to the complete callback option, the .always() method replaces the deprecated .complete() method.

Community
  • 1
  • 1
charlietfl
  • 170,828
  • 13
  • 121
  • 150