1. 程式人生 > >angular 1.6 $http.get(...).success is not a function 解決辦法

angular 1.6 $http.get(...).success is not a function 解決辦法

一、現狀

使用了angular1.6最新版,執行以前的專案報錯,按F12開啟除錯介面,控制檯輸出以下資訊$http.get(...).success is not a function,也就是說找不到success方法,同樣也找不到error方法。

二、原因

通過google一通,發現angular從1.5版本起就多了一個then方法,並不再建議使用success和error方法(but沒有移除)。但是從1.6版本開始,angular正式移除了success和error方法,這也是我們使用angular最新版跑以前的專案時候會報以上錯誤的原因。

三、解決辦法

1、方案一:使用新的then方法替代

基本語法如下:

// Simple GET request example:
$http({
  method: 'GET',
  url: '/someUrl'}).then(function successCallback(response) {
    // this callback will be called asynchronously
    // when the response is available
  }, function errorCallback(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
});

2、方案二:使用angular 1.5版本(同時相容兩種寫法)

如果是舊的專案,建議採用這種方案,否則以前的程式碼大量使用了.success()和.error()改起來會非常的蛋疼!!

四、參考

Tips:網上有些文章比較過時,大家可以優先考慮看下官方文件,示例也很齊。

相關推薦

angular 1.6 $http.get(...).success is not a function 解決辦法

一、現狀 使用了angular1.6最新版,執行以前的專案報錯,按F12開啟除錯介面,控制檯輸出以下資訊$http.get(...).success is not a function,也就是說找不到success方法,同樣也找不到error方法。 二、

.jquery(..)is not a function解決辦法

今天在做專案時,碰到了一個超奇怪的問題。我在html中的程式,跑的好好的,換成jsp在專案中跑,就一直報$ is not a function錯。找了很久,試了很多,都沒解決。後來,突然想到,將我引入的js檔案的順序換一下,將jquery的js檔案第一個引入,別的js檔案放

mongodb TypeError: db.collection is not a function 解決辦法

TypeError: db.collection is not a function 解決辦法 我也是自己踩坑(三個小時)剛剛出來的 在使用 MongoDB 資料庫 collect

ajaxfileupload.js的報錯:jQuery.handleError is not a function 解決辦法

handlerError只在jquery-1.4.2之前的版本中存在,jquery-1.4.2之後的版本中都沒有這個函數了。因此在jquery高階版本中將這個函式新增上 ,問題解決。 該js程式碼段可以加在jquer.js或者ajaxfileupload.js中。 ; (

webpack4: compilation.mainTemplate.applyPluginsWaterfall is not a function 解決方法

webpack class gin 安裝 fall log 大坑 谷歌 維護 今天搗鼓webpack4踩到一個彌天大坑:使用html-webpack-plugin打包html的時候一直報 compilation.mainTemplate.applyPluginsWaterf

$(...).on is not a function 解決方案

比如在js加入 $("p").on("click",function(){     alert("The paragraph was clicked."); }); 如果報$(…).on is not a function 錯誤 可能是你的jQuery

.finally is not a function —— 解決低版本瀏覽器axios不支援finally

框架專案用axios呼叫介面時,我們常用:介面名().then(result=>{ do sth... }).catch(()=>{ do sth... }).finally

ajaxFileUpload報錯$.ajaxFileUpload is not a function解決方法

報錯資訊 Uncaught TypeError:$.ajaxFileUpload is not a function 大意就是,ajaxFileUpload這個函式未定義 錯誤背景 我使用了ajaxFileUpload這個js來實現不借助form表單的不

TypeError: e.indexOf is not a function解決方法

This error might be caused by jquery event aliases like .load, .unload or .error deprecated since jQuery 1.8. Look for these aliases in

UnCaught TypeError:date.getFullYear is not a function解決方案

        只想看解決方案的,可看紅字!         今天在公司做專案,要求在前臺顯示一個只顯示年月日的日期。         我在資料庫存的型別是date(此處要說一下date與datetime的區別:date年月日;datetime年月日時分秒),實體類的是ja

TYPEERROR: UNDEFINED IS NOT A FUNCTION解決方法

今天除錯程式碼的時候碰到一個小問題,jQuery選擇器程式碼全部不起作用了,比如程式碼在爭取引用jQuery後呼叫$(‘.foo’)的時候還是報錯 TypeError: undefined is not a function解決方法異常簡單,原因是在把原先一個較大的js檔案

jquery.min.js?v=2.1.4:4 Uncaught TypeError: (b.contentType || "").indexOf is not a function

前臺運行 gpo 前臺 add cati json log ont fun 前臺運行PUT時出現錯誤:jquery.min.js?v=2.1.4:4 Uncaught TypeError: (b.contentType || "").indexOf is not a fun

Python: pyHook-1.5.1-cp37-cp37m-win_amd64.whl is not a supported wheel on this platform.

     pyHook-1.5.1-cp37-cp37m-win_amd64.whl is not a supported wheel on this platform. 安裝pyhook的時候報錯 下載了pyHook-1.5.1-cp37-cp37m-

angular.uppercase is not a function問題解決

專案偶遇angular.uppercase is not a function問題,使用的是AngularJs1.7.2。 百度找不到,上的必應找的, 解決方法有兩種如下(第一種已測試,第二種未測試): 1、對於1.7以上的可以在angular.module定義時加

Uncaught TypeError: $(...)[1].prev is not a function問題

其實是:JQuery選擇器得到的元素物件,和JavaScript獲取元素物件 的問題 上面兩張圖是我對 input元素的獲取,使用的兩種方式,pic1用的是原生JS方式,pic2使用的jQuery。 從列印結果可以看出來,第一個返回了我一個節點,而第二返回給我了一個數組。

jQuery 1.9 .live() is not a function

jquery中的live()方法在jquery1.9及以上的版本中已被廢棄了,如果使用,會丟擲TypeError: $(...).live is not a function錯誤。解決方法: 之前的用法:.live(events, function)  新方法: .on(

jquery-1.8.3中的BUG typeError:elem.nodeName.toLowerCase is not a function

ie和firefox一直遇到這個問題----------------------------------------------------------------------------------|   typeError:elem.nodeName.toLowerCas

Angular 懶載入報錯:TypeError:undefined is not a function

前言     Angular日常採坑     在Angular中嘗試進行懶載入時,遇到以下錯誤: TypeError:undefined is not a function 導致原因     在Ap

The requested resource is not available的解決辦法

localhost 們的 wid lib ava 路徑 available 方法 dex 以"HTTP Status 404(The requested resource is not available)"示例 HTTP Status 404(The re

Combobox報錯:row[opts.textField].toLowerCase is not a function

light peer mem div clas erro sea error () 使用easyui框架加載combobox。 html頁面: <span class="search_item">   <span class="item_text">