我正在使用 laravel 5.1
和 angularJs
进行开发。
当用户点击一个按钮时,我想发送一个destroy请求
将其从数据库中删除,然后在完成操作后发送一个get请求
以获取新的数据。
所以,我将我的方法附加到按钮的ng-click事件上,这样可以触发该方法。
然后我运行.destroy请求
。在.destroy
的.then()
方法内,我想调用另一个具有.get请求
的方法。
这在Safari中完美运行,但在Chrome或Firefox中无法正常工作。
以下是控制器的代码,被调用以删除的方法为deleteOpportunity()
:
$scope.getOpportunities = function()
{
UBOService.get()
.then(function successCallback(responsed) {
$scope.opportunities = responsed.data;
}, function errorCallback(response) {
$scope.error = response;
});
}
$scope.deleteOpportunity = function()
{
UBOService.destroy($scope.activeItem.id)
.then(function successCallback(response) {
$scope.getOpportunities();
return false;
}, function errorCallback(response) {
$scope.error = response;
});
}
我的服务代码:
app.service('UBOService', function($http) {
return {
get : function() {
return $http.get('/api/user-booked-opportunities');
},
destroy : function(id) {
return $http.delete('/api/user-booked-opportunities/' + id);
}
}
})
我是不是做错了什么?我有没有遗漏什么?Safari如何与这段代码交互,使其能够正常工作?
} $scope.deleteOpportunity = function() {
这里有帮助吗?像这样:}; $scope.deleteOpportunity = function() {
- Mark Schultheiss