After adding the item to the shopping cart, it will automatically count the price and show the total price! The statistic price function is through the front-end JS calculation, or the ID and quantity of each product to the background, and then return to the front page?
Reply content:
After adding the item to the shopping cart, it will automatically count the price and show the total price! The statistic price function is through the front-end JS calculation, or the ID and quantity of each product to the background, and then return to the front page?
To be sure, the front and back ends are calculated:
- Front-end calculation, usually through the page load after the product information, JS calculate the added shopping cart each commodity price and the total price, this is mainly the aspect of the page to show to the user, but sometimes there will be some special business circumstances complex costs (for example, sometimes will need to according to the different dynamic calculation of the purchase of the transaction fee) Will request the background computation through the Ajax and transmits the data to the front-end display;
- Back-end computing, is essential, the client passes over the data is not credible, the actual price of the calculation of the end of the main, and the front end of the calculation of the results of the verification, verification does not pass, unable to complete the subsequent logic;
In general,"both hands must grasp, both hands are hard", one for the user experience, one for the data correctness.
Both front-and back-end calculations are possible. However, it is recommended that the front-end is calculated. Proofreading (Do not trust any client-sent data, especially qianming-like transactions)
The front-end data is for the user to see. Finally only the future end of the prevail. Therefore, both ends are calculated, but the meaning is different.
Supposedly the front-end can also, but still use the back end to calculate it, because the front-end calculation will have problems, if not considered too accurate, front-end no problem!