gpt4 book ai didi

javascript - Angular .js 错误 : Expected response to contain an array but got an object although isArray is set to false

转载 作者:行者123 更新时间:2023-11-29 19:44:01 40 4
gpt4 key购买 nike

我有一个 Angular 资源工厂,它返回一个 JSON 对象,如下所示:

angular.module('myApp').factory('resourceProvider', function ($resource, $http) {
return {
Attribute: $resource('http://localhost:49980/api/Attribute/:id',
{ id: '@id' }, { query: { method: 'GET', isArray: false } }),
};
});

当我像这样“查询”资源时:

resourceProvider.Attribute.query(function (data) {
$scope.variable = data;
});

我得到:错误:[$resource:badcfg] 资源配置错误。预期响应包含一个数组但得到一个对象。

这对我来说似乎很奇怪,因为我将 isArray 设置为 false。此外,该代码在其他电脑上运行良好。因此,如果有人知道错误可能来自何处,我将非常感激。

最佳答案

问题解决了。数据库身份验证出现问题,错误消息恰好是一个 JSON 对象。所以实际上返回了一个 JSON 对象而不是一个数组。

关于javascript - Angular .js 错误 : Expected response to contain an array but got an object although isArray is set to false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21187342/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com