【发布时间】:2021-02-01 18:30:47
【问题描述】:
我已经使用 angularJS 路由构建了一个单页应用程序。我有一个购物车页面,用户在其中选择了产品并可以继续结帐。
如果您单击按钮,您将被重定向到结帐页面。
问题是我对总成本进行了硬编码,我想使用 jquery 或 ajax 将其从产品页面传递到结帐页面。我显然可以使用 localstorage 但如果我切换回我的产品页面并编辑价格然后返回结帐,因为没有重新加载发生 localstorage 显示以前的总数。这就是我需要 jquery 或 ajax 解决方案的原因。
我的代码:
//-----Click Checkout button ------
$("#checkOut").click(()=>{
//get count of products
var numOfProducts = $('.product-columns').length;
if(numOfProducts!=0){
//pass total cost to variable
var total = $('.FinalTotal').text();
//append total cost to html total cost element of checkout.php
window.location.href='../php/index.php#!/purchase';
}else{
alert("Your cart is empty");
}
});
products.php 中的总计
<p> Total </p>
<span class="new__price FinalTotal">$0</span>
<a href="" id ="checkOut">PROCEED TO CHECKOUT</a>
购买.php
<h2 id = "totalPrice"> Total Price : </h2>
单页应用的angularjs路由
app.config(($routeProvider)=>{
$routeProvider
.when("/" , {templateUrl:"main.php"})
.when("/login" , {templateUrl : "login.php"})
.when("/register" , {templateUrl : "register.php"})
.when("/results" , {templateUrl : "showResults.php"})
.when("/purchase", {templateUrl:"purchase.php"})
.when("/cart" ,{templateUrl:"products.php"});
});
【问题讨论】:
标签: javascript php jquery ajax