JavaScript-is the price statistics for the shopping cart on the e-commerce site calculated as front-end or back-office?

Source: Internet
Author: User
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!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.