Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 本地和服务器运行之间意外不匹配_Javascript_Angularjs_Eclipse_Jsp_Azure - Fatal编程技术网

Javascript 本地和服务器运行之间意外不匹配

Javascript 本地和服务器运行之间意外不匹配,javascript,angularjs,eclipse,jsp,azure,Javascript,Angularjs,Eclipse,Jsp,Azure,我已经创建了一个eshop,当我在Eclipse本地运行项目时,当用户单击按钮“立即订购”时,下面附加的脚本就会执行。在此之后,购物车项目至少有1个产品 我已经在Azure上上传了该项目,现在订购按钮的操作不正常 viewProduct.jsp <!-- Import spring text --> <%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%> <%@taglib p

我已经创建了一个eshop,当我在Eclipse本地运行项目时,当用户单击按钮“立即订购”时,下面附加的脚本就会执行。在此之后,购物车项目至少有1个产品

我已经在Azure上上传了该项目,现在订购按钮的操作不正常

viewProduct.jsp

<!-- Import spring text -->
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@include file="/WEB-INF/views/template/header.jsp"%>


<div class="container-wrapper">
    <div class="container">
        <div class="page-header">
            <h1>Product Detail</h1>

            <p class="lead">Here is the detail information of the product</p>
        </div>

        <!-- Grid system from Bootstrap -->
        <div class="container" ng-app="cartApp">
            <div class="row">
                <div class="col-md-5">
                    <img
                        src="<c:url value="/resources/images/${product.productId}.png" /> "
                        alt="image" style="width: 100%" />
                </div>
                <div class="col-md-5">
                    <h3>${product.productName}</h3>
                    <p>${product.productDescription}</p>
                    <p>
                        <strong>Manufacture</strong> : ${product.productManufacture}
                    </p>
                    <p>
                        <strong>Category</strong> : ${product.productCategory}
                    </p>
                    <p>
                        <strong>Condition</strong> : ${product.productCondition}
                    </p>
                    <p>${product.productPrice}USD</p>

                    <br>

                    <c:set var="role" scope="page" value="${param.role}" />
                    <c:set var="url" scope="page" value="/product/productList" />
                    <!-- if the user is admin we change the back page for the following "back" button -->
                    <c:if test="${role='admin'}">
                        <c:set var="url" scope="page" value="/admin/productInventory" />
                    </c:if>

                    <p ng-controller="cartCtrl">
                        <a href="<c:url value="${url}" />" class="btn btn-default">Back</a>
                        <!-- we use the angular funtction (#)  -->
                        <a href="#" class="btn btn-warning btn-large"
                            ng-click="addToCart('${product.productId}')"><span
                            class="glyphicon glyphicon-shopping-cart"></span>Order Now</a>

                        <a href="<spring:url value="/customer/cart" />" class="btn btn-default"><span
                            class="glyphicon glyphicon-hand-right"></span>View Cart</a>
                    </p>
                </div>
            </div>
        </div>

    </div>
</div>

<script src="<c:url value="/resources/js/controller.js" /> "></script>
<%@include file="/WEB-INF/views/template/footer.jsp"%>

产品详情

以下是产品的详细信息

" alt=“image”style=“宽度:100%”/> ${product.productName} ${product.productDescription}

制造:${product.productManufacture}

类别:${product.productCategory}

条件:${product.productCondition}

${product.productPrice}美元


cart.jsp文件中,我还尝试从controller.js执行clearCart()。代码也不会运行

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@include file="/WEB-INF/views/template/header.jsp" %>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
<script src="<c:url value="/resources/js/controller.js" /> "></script>

<div class="container-wrapper">
    <div class="container">
        <section>
            <div class="jumbotron">
                <div class="container">
                    <h1>Cart</h1>

                    <p>All the selected products in your shopping cart</p>
                </div>
            </div>
        </section>

        <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>
                <a href="<spring:url value="/order/${cartId}"/>"
                   class="btn btn-success pull-right"><span class="glyphicon-shopping-cart glyphicon"></span> Check out
                </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="glyphicon glyphicon-remove"></span>remove</a></td>
                </tr>
                <tr>
                    <th></th>
                    <th></th>
                    <th>Grand Total</th>
                    <th>{{calGrandTotal()}}</th>
                    <th></th>
                </tr>
            </table>

            <a href="<spring:url value="/" />" class="btn btn-default">Continue Shopping</a>
            </div>
        </section>

    </div>
</div>


<%@include file="/WEB-INF/views/template/footer.jsp" %>

运货马车
您购物车中的所有选定产品

产品 单价 量 价格 行动 {{item.product.productName} {{item.product.productPrice} {{item.quantity} {{item.totalPrice} 总计 {{calGrandTotal()}}
controller.js

var cartApp = angular.module ("cartApp", []);

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

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

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

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

    $scope.addToCart = function (productId) {
        $http.put('/eMusicStore/rest/cart/add/'+productId).success(function () {
            alert("Product successfully added to the cart!")
        });
    };

    $scope.removeFromCart = function (productId) {
        $http.put('/eMusicStore/rest/cart/remove/'+productId).success(function (data) {
            $scope.refreshCart();
        });
    };

    $scope.calGrandTotal = function () {
        var grandTotal=0;

        for (var i=0; i<$scope.cart.cartItems.length; i++) {
            grandTotal+=$scope.cart.cartItems[i].totalPrice;
        }

        return grandTotal;
    };
});
var cartApp=angular.module(“cartApp”,[]);
控制器(“cartCtrl”,函数($scope,$http){
$scope.refreshCart=函数(){
$http.get('/eMusicStore/rest/cart/'+$scope.cartId).success(函数(数据){
$scope.cart=数据;
});
};
$scope.clearCart=函数(){
$http.delete('/eMusicStore/rest/cart/'+$scope.cartId).success($scope.refreshCart());
};
$scope.initCartId=函数(cartId){
$scope.cartId=cartId;
$scope.refreshCart(cartId);
};
$scope.addToCart=函数(productId){
$http.put('/eMusicStore/rest/cart/add/'+productId).成功(函数(){
警报(“产品已成功添加到购物车!”)
});
};
$scope.removeFromCart=函数(productId){
$http.put('/eMusicStore/rest/cart/remove/'+productId).成功(函数(数据){
$scope.refreshCart();
});
};
$scope.calGrandTotal=函数(){
var-grandTotal=0;

对于(var i=0;i请尝试以下代码来记录HTTP错误响应

$http.put('/eMusicStore/rest/cart/remove/'+productId).success(function (data) {
    $scope.refreshCart();
}).error(function (data, status, header, config) {
    console.log(data);    
});

“不能正常工作”是什么意思?它到底是如何工作的?您是否收到任何错误消息(在服务器日志中,在浏览器控制台中)?@JozefChocholacek无错误。我现在单击Order,Angular代码不会执行,因为addToCart函数中的警报没有出现。因此我认为Angular代码永远不会执行。你能在addToCart函数的第一行添加一个
警报
,检查它是否被调用吗?我意识到这个问题不仅在服务器中。我已将警报添加到所有功能中。当我在viewProduct.jsp上并单击“立即订购”时,将执行controller.js发出的警报。当我单击购物车(以查看当前产品)时我看到以下警报:来自initCart、refreshCart、calGrandTotal,然后是相同序列的相同警报。所有这些代码都来自e-course。但我认为存在一些问题。我可以看到initCartId中refreshCart有一个参数(cartId)但是在refreshCart的定义中没有参数!在此之后,函数calGrandTotal没有参数。那么这个函数如何尝试找到grandTotal的结果呢?我想了解一下我所说的内容是否不适用,但我在角度上确实是初级的。经过太多的尝试(并回顾创建购物车开始时的一些项目)当前的错误是。严重错误:路径为[/eMusicStore]的上下文中Servlet[SpringMVC]的Servlet.service()抛出异常[Handler processing failed;嵌套异常为java.lang.StackOverflower]关于根本原因java.lang.StackOverflowerr,我在一周前询问了这个错误。有人给了我一个链接,但我找不到哪里出了问题。