购物车价格统计是前端计算还是后台计算?

PHPz
Release: 2020-06-28 09:31:36
Original
3681 people have browsed it

购物车价格统计是前端计算还是后台计算?

购物车价格统计是前端计算还是后台计算?

具体问题:

添加了商品到购物车后,就会自动统计价格,显示总价格!那这个统计价格功能是通过前端js计算的,还是把每个产品的id以及数量传给后台,计算完再返回给前端页面呢?

回复:

可以肯定的说,前端和后端都要计算:

前端计算,一般是通过页面加载后的商品信息,JS计算出添加后的购物车每个商品价格和总价格,这主要是方面页面展示给用户,只是有时候会有一些特殊业务情况下的复杂费用(例如有时会需要根据根据购买商品的不同动态计算手续费)会通过Ajax来请求后台计算并传递数据给前端展示;

后端计算,是必不可少的,客户端传递过来的数据是不可信的,实际的价格肯定以后端的计算为主,并对前端传递的计算结果进行校验,校验不通过,无法完成后续逻辑;

综合而言,“两手都要抓,两手都要硬”,一为用户体验,一为数据正确性。

更多相关技术文章,请访问PHP中文网

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!