2017-04-14 32 views
1

我突然開始得到以下:

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

我的代碼:

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 
       }); 
     }; 

這是怎麼發生的?我更新了jQuery - 是否有一些此語法失效?

+0

是; 'complete'已被棄用,因爲jQuery 3.0 – Hamms

+0

@Hamms我應該用什麼來代替? – user666

+0

'always'; [docs](http://api.jquery.com/jquery.ajax/)也有這個信息 – Hamms

回答

2

.complete已被棄用....使用.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.