【问题标题】:Ajax GET returns Object #<Object> has no method 'slice' errorAjax GET 返回 Object #<Object> has no method 'slice' 错误
【发布时间】:2014-08-09 15:37:00
【问题描述】:

我进行以下 ajax 调用,

$scope.clientList = [];
                     $http({
                     method: 'GET',
                     isArray: true,
                     url: "https://localhost/api/Client",
                     params: sort,

                 }).success(function (data, status, headers, config) {
                            $scope.clientList = data;

                     }). error(function (data, status, headers, config) {

                     });

我得到一个数组作为数据的结果。 但我得到一个错误,

TypeError: Object #<Object> has no method 'slice'

尽管添加了 isArray: true。

我缺少什么?

【问题讨论】:

  • 这不是 jQuery。您确定返回的对象可以在没有任何特殊解析的情况下转换为数组吗?编辑,它看​​起来不像 $http 可以使用 isArray 参数,因为它是 $resource 的一部分
  • @BenFortune:是的..你是对的,我的错:(

标签: ajax arrays angularjs get typeerror


【解决方案1】:
$scope.clientList = [];
                 $http({
                 method: 'GET',
                 isArray: true,
                 url: "https://localhost/api/Client",
                 params: sort,

             }).success(function (data, status, headers, config) {
                        $scope.clientList = data.data;

                 }). error(function (data, status, headers, config) {

抱歉,这是一个简单的转换问题。正在分配对象而不是返回的对象内的数组。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多