我有这段代码。我尝试了3种类型的ajax调用,但没有人工作。我收到同样的错误:
var getTableData = function() {
var defer = $q.defer();
$http.get('api/carregargridamenidades').then(function(result) {
defer.resolve(result.data);
});
return defer.promise;
};
//first option
$scope.dtOptions = DTOptionsBuilder
.newOptions()
.fromFnPromise(function() { (1)
return $resource('api/carregargridamenidades').query().$promise;
})
.withBootstrap()
.withOption('processing', true)
.withPaginationType('full_numbers');
//second option
$scope.dtOptions = DTOptionsBuilder
.newOptions()
.fromSource(getTableData()) (2)
.withBootstrap()
.withOption('processing', true)
.withPaginationType('full_numbers');
//Third option
$scope.dtOptions = DTOptionsBuilder
.newOptions()
.withOption('ajax', { (3)
url: 'api/carregargridamenidades'
})
.withBootstrap()
.withOption('processing', true)
.withPaginationType('full_numbers');
各自的错误:
(1) TypeError: DTOptionsBuilder.newOptions(...).fromFnPromise is not a function
at new <anonymous> (amenidade-controller.js:47)
at Object.invoke (angular.min.js:41)
at S.instance (angular.min.js:89)
at p (angular.min.js:65)
at g (angular.min.js:58)
at g (angular.min.js:58)
at g (angular.min.js:58)
at g (angular.min.js:58)
at g (angular.min.js:58)
at g (angular.min.js:58)
(2) TypeError: DTOptionsBuilder.newOptions(...).fromSource is not a function
at new <anonymous> (amenidade-controller.js:43)
at Object.invoke (angular.min.js:41)
at S.instance (angular.min.js:89)
at p (angular.min.js:65)
at g (angular.min.js:58)
at g (angular.min.js:58)
at g (angular.min.js:58)
at g (angular.min.js:58)
at g (angular.min.js:58)
at g (angular.min.js:58)
(3) Uncaught TypeError: Cannot read property 'length' of undefined
at jquery.dataTables.min.js:48
at i (jquery.dataTables.min.js:35)
at Object.success (jquery.dataTables.min.js:35)
at i (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at A (jquery.min.js:4)
at XMLHttpRequest.<anonymous> (jquery.min.js:4)
我正在使用下面的angular-datatables版本:
/ *! * angular-datatables - v0.5.5 * https://github.com/l-lin/angular-datatables *许可证:麻省理工学院 * /
我从Laravel 5.3控制器中获取数据,例如:
public function carregarGrid()
{
//Recupera todos os objetos cadastrados
$objs = Amenidade::all();
return $objs;
}
我的愿望是#34;正在加载......&#34;消息出现在数据表中,而我的ajax正在获取数据,但这个简单的步骤让我发疯。我正在使用来自stackoverflow和angular-datatables站点(http://l-lin.github.io/angular-datatables/archives/#/api)的建议。
对于这个简单的问题,有一个简单的解决方案吗?
感谢。