2017-03-14 15 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); 
    }); 
相關問題