Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 381
BLAZORLOVER Avatar asked Jan 04 '23 04:01

BLAZORLOVER


1 Answers

.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.

like image 50
charlietfl Avatar answered Jan 06 '23 18:01

charlietfl