2016-12-27 129 views
1

我試圖使用下面的代碼解析json,但它顯示一個空白頁。

var app = angular.module('myApp', []); 
app.controller('myCtrl', function($scope, $http) { 
    $http.get("http:krispypapad.herokuapp.com/fetch_article").success(function (response) { 
     $scope.myWelcome = data.response; 

    }); 
}); 
+0

參見[爲什麼角$ HTTP成功/錯誤的方法已過時?從v1.6中刪除?](http://stackoverflow.com/a/35331339/5535245)。 – georgeawg

回答

1

我認爲有錯字與正在使用的網址:

http:krispypapad.herokuapp.com代替http://krispypapad.herokuapp.com你缺少幾個//

這是你的代碼將如何看起來像:

var app = angular.module('myApp', []); 
app.controller('myCtrl', function($scope, $http) { 
    $http.get("http://krispypapad.herokuapp.com/fetch_article").success(function (response) { 
     $scope.myWelcome = response; //<-- no .data is required 

    }); 
}); 
+0

'.success'方法不返回響應對象。改爲使用'.then'方法。 – georgeawg

0

您在網址中有錯字,它應該是這樣的:

http://krispypapad.herokuapp.com/whatever 

而且你應該使用response.datadata.response

+0

'.success'方法不返回響應對象。改爲使用'.then'方法。 – georgeawg