本文介绍了无法读取AngularJS $资源响应DELETE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用AngularJS $资源,从我的服务器删除数据。然而,当我写的结果来安慰,我没有看到的数据。

然而,当我进入网络在Chrome的控制台,我看到名称路径左列中删除。当我点击信息,我看到右侧面板上五个选项卡,根据preVIEW和响应选项卡上,我看到了正确的数据。我只是不知道怎么看或检索,在我的javascript。

下面是JavaScript服务code:

  VAR MyServices = angular.module('MyServicesName',['ngResource']);MyServices.factory('AAAService',函数($资源){
    返回$资源(serverBaseUrl +用户/:用户名/视频/:VIDEOID /',{用户名:@userId',VIDEOID:@videoId'},{
        显示:{方法:GET},
        更新:{方法:把',则params:{ID:'@id'}},
        删除:{方法:删除,IsArray的:假}
    });
});

和控制器:

  quizcatControllers.controller('BBBCtrl',['$范围,$ stateParams,$ HTTP,AAAService',
    功能($范围,$ stateParams,$ HTTP,AAAService){
$ scope.deleteQuestion =功能(用户,VIDEOID){
             AAAService.delete({用户名:用​​户,VIDEOID:VIDEOID}功能(A,B){
        的console.log(一); //期望打印的数据
        的console.log(B);
});

可有人建议我的code应如何改变这样我可以从获取响应的数据?
虽然我的响应数据是不是在阵列格式,我想知道如何做到这一点为:阵列和阵列没有风格

应该是什么正确的名称,而不是A和B上以下行:

UPDATE:

This is the result I get in the success callback for the parameter returnValue:

解决方案

Using resources can be a bit confusing (at least they originally were for me).

I think your problem is that your call to delete isn't using the correct signature (there are different signatures for 'GET' methods and 'non-GET' methods. In this case, it looks like you are sending what is intended to be your callback function (for success and error) as postData. The signature you used is for 'GET' methods (which doesn't have postData).

The signature for your call to delete should look like this (see documentation here):

So, you can do something like this:

quizcatControllers.controller('BBBCtrl', ['$scope', '$stateParams', '$http', 'AAAService',
function($scope, $stateParams, $http, AAAService) {
    $scope.deleteQuestion = function(user, videoId) {
        AAAService.delete(
            {userId: user, videoId: videoId},  // parameters
            {},                                // postData, which you don't need for this
            // success callback
            function (returnValue, responseHeaders) {
                // do what you want with the returnValue from the call here
            },
            // error callback
            function (httpResponse) {
                // do what you want for error handling here
            })
    };
}]);

这篇关于无法读取AngularJS $资源响应DELETE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 00:42
查看更多