我有一個視圖,調用下面這個函數使得我們的API的AJAX調用 - 由於某種原因,當我在AngularScope中使用AngularScope時,總是返回'undefined' Firefox DOM檢測工具。如何從AJAX調用(AngularJS)正確地返回我的數據
如果我檢查網絡標籤,我可以看到這個URL已被調用,並可以看到我期待的JSON,然後我想返回data.words JSON數據,但是這總是返回undefined?如果我刪除了AJAX調用,並且在最後一次返回時使用了「靜態」和「單詞」,這在我看來很有效,所以我很清楚AJAX成功調用的返回似乎並不正確... 有任何想法嗎??
//內的AngularJS服務文件
this.getAccSignoffWords = function() {
var url = ApiService.getDomain() + 'account/signoff';
$http({
method : 'GET',
url : url
}).success(function(data) {
if (data.success) {
return data.words; // I want to return this JSON to the scope
}
}).error(function(data) {
throw "Failed to get sign-off words";
})['finally'](function(data) {
});
// return [ 'static', 'words' ]; // this line is commented out and only used for testing and is an example of the type of data expected from data.words
}
這個函數嘗試解析在成功調用數據傳回:'數據= JSON.parse(數據)' –
嗨Nishanth,其中這應該放在 - 我要刪除成功塊內的當前返回 – Zabs
嗯仍然沒有喜悅使用,在成功塊.. :( – Zabs