2017-03-14 14 views
0

我有以下代码,但我不确定如何向请求添加成功/错误处理程序。

$resource('/example.json', {}, { 
    get_something: 
    method: 'POST' 
    url: '/example/get_something.json' 
}) 

我想我应该能够添加success:或类似的东西在这里,但显然事实并非如此。完成此请求后,我该怎么做?

+0

使用'$ promise.then'。你可以参考这个链接:http://stackoverflow.com/questions/15531117/resource-callback-error-and-success –

回答

0

可以处理响应(成功/错误/除外)如下:

var example = $resource('/example.json', {}, { 
    get_something: { 
     method: 'GET' 
    } 
}); 

var postParams = {}; // Define post params if any. If you have any post params just use example.get_something() 
example.get_something(postParams) 
    .$promise.then(function(response) { 
     console.log(response); 
    }, function(error) { 
     console.log(error); 
    }) 
    .catch(function(exception) { 
     console.log(exception); 
    }); 
相关问题