![](/img/trans.png)
[英]How to return json object from jsp to angularjs ajax http.get?
[英]AngularJS access JSON Object returned from $http.get
我嘗試訪問由Google API生成的json對象。
function getAvengers() {
return $http.get('https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA')
.then(getAvengersComplete)
.catch(getAvengersFailed);
function getAvengersComplete(response) {
return response.data;
}
function getAvengersFailed(error) {
console.log('XHR Failed for getAvengers.' + error.data);
}
}
TestCtrl.dataTest = dataservice.getAvengers();
console.log(TestCtrl.dataTest.status);
日志生成未定義。 你可以幫幫我嗎?
謝謝
當getAvengers
返回承諾時,您不能將其結果用作立即值,但可以訂閱其分辨率。 有關更多詳細信息,請參見Promise教程 。
function getAvengers() {
return $http.get('https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA')
.then(getAvengersComplete)
.catch(getAvengersFailed);
function getAvengersComplete(response) {
return response.data;
}
function getAvengersFailed(error) {
console.log('XHR Failed for getAvengers.' + error.data);
}
}
TestCtrl.dataTest = null;
dataservice.getAvengers().then(function(data) {
TestCtrl.dataTest = data;
console.log(TestCtrl.dataTest.status);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.