我有一个视图,调用下面这个函数使得我们的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