后端有個接口,請求/api/avatar/這個網址時,返回一個圖片的實際路徑/static/images/uploads/default,在瀏覽器中測試是完全OK的,如圖:但使用angular的get方法,代碼如下:var myapp = angular.module("myapp", []);myapp.controller("MainCtrl", ["$http", function ($http) { var self = this; this.get_avatar = function () { $http({ method: "GET", url: "/api/avatar/" }).then(function (value) { console.log(value.data); return value.data; }, function (reason) { console.log(reason); }) };}]);在html中使用<img ng-src="{{ctrl.get_avatar()}}">去獲取圖片地址,此時一打開html,前端瘋狂向后端發送get請求,如圖:瀏覽器console中也不斷地重復刷出錯誤,如圖:
angularjs發送get請求出現錯誤
滄海一幻覺
2019-03-12 16:15:33