Javascript 单击角复选框,$resource将导致SecurityException:操作不安全

Javascript 单击角复选框,$resource将导致SecurityException:操作不安全,javascript,angularjs,asp.net-web-api,dynamics-crm,Javascript,Angularjs,Asp.net Web Api,Dynamics Crm,我尝试将angular.js与对Microsoft Dynamics CRM webapi端点的调用结合起来 该网页将项目列表显示为复选框。勾选未勾选的复选框应执行关联。取消勾选复选框应执行解除关联 您将在下面的代码中看到,关联确实有效,但解除关联却无效。我无法设置plunker,因为代码与Microsoft Dynamics CRM应用程序绑定 首先,HTML部分 <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.or

我尝试将angular.js与对Microsoft Dynamics CRM webapi端点的调用结合起来

该网页将项目列表显示为复选框。勾选未勾选的复选框应执行关联。取消勾选复选框应执行解除关联

您将在下面的代码中看到,关联确实有效,但解除关联却无效。我无法设置plunker,因为代码与Microsoft Dynamics CRM应用程序绑定

首先,HTML部分

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="../../ClientGlobalContext.js.aspx"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular-resource.min.js"></script>
    <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <!-- Optional theme -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    <script src="crmwebapimodule.js"></script>
    <script src="manyrelationshipapp.js"></script>
</head>
<body ng-app="crmApp">
    <div ng-controller="AppController" class="col-sm-7 col-md-2">
        <div ng-repeat="match in matches">
            <input type="checkbox" id="{{match.recordId}}" ng-model="match.checked" ng-click="doAction(match.recordId, match.checked)" />
            <span for="{{match.recordId}}">{{match.label}}</span>
        </div>
    </div>
</body>
</html>
最后,控制器本身

/// <reference path="CrmWebApiModule.js" />
(function () {
    // create a module for our Angular app with a dependency on our angularMscrm module
    var CrmApp = angular.module('crmApp', ['ManyRelationshipAngularMscrm']);

    // create a controller for the page, and inject our CrmService into it
    CrmApp.controller('AppController', function ($scope, CrmWebApiService) {
        // Data for test purpose
        var params =
        {
            recordId: '{32A33A4B-99A4-E511-80C0-00155D0A061D}',
            primaryEntitySet: 'opportunities',
            primaryIdAttr: 'opportunityid',
            primaryField: 'name',
            secondaryEntitySet: 'competitors',
            secondaryIdAttr: 'competitorid',
            secondaryPrimaryField: 'name',
            entityRelationSet: 'opportunitycompetitors_association'
        };

        if (params.recordId.length == 38) {
            params.recordId = params.recordId.substr(1, 36);
        }

        $scope.matches = new Array();

        $scope.doAction = function (id, value) {
            if (value === true) { 
                CrmWebApiService.Associate({
                    primaryEntitySet: params.primaryEntitySet,
                    entityId: params.recordId,
                    entityRelationName: params.entityRelationSet
                },
                {
                    "@odata.id": Xrm.Page.context.getClientUrl() + '/API/data/v8.1/' + params.secondaryEntitySet + '('+ id +')'
                }, function(response) {
                     alert(httpResponse);
                });
            } else {
                CrmWebApiService.Disassociate({
                    primaryEntitySet: params.primaryEntitySet,
                    primaryEntityId: params.recordId,
                    entityRelationName: params.entityRelationSet,
                    secondaryEntityId: id
                }, function (response) {

                },
                function(httpResponse) {
                    alert(httpResponse);
                });
            }

        }

        CrmWebApiService.GetActiveItems({
            entitySet: params.secondaryEntitySet,
            primaryField: params.secondaryPrimaryField
        },
            function (response) {
                var data = response.value;

                for (var i = 0; i < data.length; i++) {
                    $scope.matches.push({
                        recordId: data[i][params.secondaryIdAttr].toLowerCase(),
                        label: data[i][params.secondaryPrimaryField],
                        checked: false
                    });
                }
            });

        CrmWebApiService.GetSelectedItems({
            entitySet: params.primaryEntitySet,
            primaryEntityId: params.recordId,
            primaryField: params.primaryField,
            entityRelationName: params.entityRelationSet,
            secondaryPrimaryField: params.secondaryPrimaryField
        },
            function (response) {
                var data = response[params.entityRelationSet];

                for (var i = 0; i < $scope.matches.length; i++) {
                    for (var j = 0; j < data.length; j++) {
                        if ($scope.matches[i].recordId === data[j][params.secondaryIdAttr]) {
                            $scope.matches[i].checked = true;
                            break;
                        }
                    }
                }
            });
    });
}());
//
(功能(){
//为Angular应用程序创建一个模块,该模块依赖于angularMscrm模块
var CrmApp=angular.module('CrmApp',['ManyRelationshipAngularMscrm']);
//为页面创建一个控制器,并将我们的CrmService注入其中
CrmApp.controller('AppController',函数($scope,crmWebAPI服务){
//测试用数据
变量参数=
{
记录ID:“{32A33A4-99A4-E511-80C0-00155D0A061D}”,
primaryEntitySet:“机会”,
PrimaryDiattr:“机会性ID”,
primaryField:'名称',
第二实体集:“竞争对手”,
第二名:“竞争对手”,
secondaryPrimaryField:'名称',
entityRelationSet:“机会竞争者协会”
};
if(params.recordId.length==38){
params.recordId=params.recordId.substr(1,36);
}
$scope.matches=新数组();
$scope.doAction=函数(id,值){
如果(值===true){
crmwebapise.Associate({
primaryEntitySet:params.primaryEntitySet,
entityId:params.recordId,
entityRelationName:params.entityRelationSet
},
{
“@odata.id”:Xrm.Page.context.getClientUrl()++'/API/data/v8.1/'+params.secondaryEntitySet++'('+id++')”
},功能(回应){
警报(httpResponse);
});
}否则{
crmWebAPI服务。解除关联({
primaryEntitySet:params.primaryEntitySet,
primaryEntityId:params.recordId,
entityRelationName:params.entityRelationSet,
secondaryEntityId:id
},功能(回应){
},
功能(httpResponse){
警报(httpResponse);
});
}
}
crmWebAppIservice.GetActiveItems({
entitySet:params.secondaryEntitySet,
primaryField:params.secondaryPrimaryField
},
功能(响应){
var数据=响应值;
对于(变量i=0;i
Soo,关联按预期工作,但解除关联会导致以下错误:

Error: The operation is insecure.
hf/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:84:6
s@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:80:22
m/f<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:77:308
f/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:107:349
Ge/this.$get</k.prototype.$eval@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:121:189
Ge/this.$get</k.prototype.$digest@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:118:296
Ge/this.$get</k.prototype.$apply@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:121:458
tc[c]</<.compile/</<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:220:167
$e/c@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:32:253
e/<()angular.min.js (ligne 99)
ye/this.$get</<(a=Object { type="object"}, c=undefined)angular.min.js (ligne 74)
f/<()angular.min.js (ligne 107)
Ge/this.$get</k.prototype.$eval(a=Object { type="object"}, b=undefined)angular.min.js (ligne 121)
Ge/this.$get</k.prototype.$digest()angular.min.js (ligne 118)
Ge/this.$get</k.prototype.$apply(a=Object { type="object"})angular.min.js (ligne 121)
tc[c]</<.compile/</<(d=Object { type="object"})angular.min.js (ligne 220)
$e/c(c=Object { type="object"}, e=undefined)angular.min.js (ligne 32)
错误:操作不安全。

hf/Hey Tanguy,欢迎来到SO,这是很多代码,这是这个问题严格要求的吗?您认为可以对其进行编辑以创建一个最小、完整且可验证的示例吗。这将使我们更容易回答。您是否尝试使用Postman复制代码生成的HTTP DELETE请求?也可能是打字错误,但在单词delete('delete')@JamesWood后面有一个空格,因为我是Angular的新手,我想我可能犯了一些愚蠢的错误。这就是我发布所有代码的原因好吧,很抱歉,@GuidoPreite找到了解决方案。。。只是这该死的额外空间我没有notice@TanguyTouzard很高兴你解决了:)
Error: The operation is insecure.
hf/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:84:6
s@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:80:22
m/f<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:77:308
f/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:107:349
Ge/this.$get</k.prototype.$eval@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:121:189
Ge/this.$get</k.prototype.$digest@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:118:296
Ge/this.$get</k.prototype.$apply@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:121:458
tc[c]</<.compile/</<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:220:167
$e/c@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js:32:253
e/<()angular.min.js (ligne 99)
ye/this.$get</<(a=Object { type="object"}, c=undefined)angular.min.js (ligne 74)
f/<()angular.min.js (ligne 107)
Ge/this.$get</k.prototype.$eval(a=Object { type="object"}, b=undefined)angular.min.js (ligne 121)
Ge/this.$get</k.prototype.$digest()angular.min.js (ligne 118)
Ge/this.$get</k.prototype.$apply(a=Object { type="object"})angular.min.js (ligne 121)
tc[c]</<.compile/</<(d=Object { type="object"})angular.min.js (ligne 220)
$e/c(c=Object { type="object"}, e=undefined)angular.min.js (ligne 32)