当我单击按钮时,角度不起作用…Spring mvc

问题描述 投票:0回答:1

当我在cart.jsp上单击清除按钮时,出现此错误-> angular.js:13565 DELETEhttp://localhost:8080/rest/cart/D79B4033A5B442A3EDA7CEBF932F9BBE403。

并且当我单击立即订购时,什么也没有发生。

我到处都搜索错误,但找不到。

您能帮我!!

controller.js


cartApp.controller("cartCtrl", function($scope,$http){

    $scope.refreshCart = function (cartId) {
        $http.get('/rest/cart/'+$scope.cartId).then(function (data) {
           $scope.cart=data;
        });
    };

    $scope.clearCart=function(){
        $http.delete('/rest/cart/'+$scope.cartId).then($scope.refreshCart($scope.cartId));
    };

    $scope.initCartId=function(cartId){
        $scope.cartId=cartId;
        $scope.refreshCart(cartId);
    };

    $scope.addToCart=function(productId){
        $http.put('/rest/cart/add/'+productId).then(function(data){
            $scope.refreshCart($http.get('/rest/cart/cartId'));
            alert("product successfully added to the cart")
        });
    };

    $scope.removeFromCart=function(productId){
        $http.put('/rest/cart/remove/'+productId).then(function(data){
            $scope.refreshCart($http.get('/rest/cart/cartId'));
            alert("product successfully removed from the cart")
        });
    };
});

cart.jsp

<section class="container" ng-app="cartApp">
            <div  ng-controller = "cartCtrl" ng-init="initCartId('${cartId}')">

            <div>
                <a class="btn btn-danger pull-left" ng-click="clearCart()"><span class="glyphicon glyphicon-remove-sign"></span>Clear Cart </a>
            </div>
            <table class="table table-hover">
                <tr>
                    <th>Product</th>
                    <th>Unit Price</th>
                    <th>Quantity</th>
                    <th>Price</th>
                    <th>Action</th>
                </tr>
                <tr ng-repeat="item in cart.cartItems">
                    <td>{{item.product.productName}} </td>
                    <td>{{item.product.productPrice}}</td>
                    <td>{{item.quantity}}</td>
                    <td>{{item.totalPrice}}</td>
                    <td><a href="#" class="label label-danger" ng-click="removeFromCart(item.product.productId)">
                    <span class="glyhicon glyhicon-romove">Remove</span></a></td>
                </tr>
                <tr>
                    <th></th>
                    <th></th>
                    <th>Grand Total: </th>
                    <th>{{cart.grandTotal}}</th>
                    <th></th>
                </tr>
            </table>
            <a href="<spring:url value="/productList"/> " class="btn btn-default">Continue Shopping</a>
            </div>
        </section>

product.jsp

                <p ng-controller="cartCtrl">
                    <a href="#" class="btn btn-warning btn-large" 
                    ng-click="addToCart('${product.productId}')">
                    <span class="glyphicon glyphicon-shopping-cart"></span>Order Now</a>
                </p>
angularjs spring-mvc spring-restcontroller
1个回答
0
投票

403表示您需要配置Spring安全性以允许该请求

© www.soinside.com 2019 - 2024. All rights reserved.