It's a question of the quantity of the shopping cart.

Asked 1 years ago, Updated 1 years ago, 413 views

I'm working on the quantity of the shopping cart. At first, I thought I could just change the quantity to JavaScript and pass the price to the order, but when I think about it, even if I log out and log in again, the quantity should remain changed. Then, I thought that if I changed the quantity, I would have to save the price in db right away, so I did it up to there for now. But I only know how to refresh the page as soon as I change the quantity... I looked it up and said I could use ajax, but I don't know exactly how to use it... In the current controller, when you press the - button, the count becomes -1, and the + button becomes +1, and the page is loaded. I'll post it as a reference below.

@RequestMapping("/cart_update_plus")
    public String cart_update_plus(@RequestParam("status_idx") int status_idx, HttpServletRequest request, Model model) {
        int idx = (int) request.getSession().getAttribute("user_idx");
        int update_plus = iBasketdao.update_plus( idx, status_idx );
        List<BasketDto> list = iBasketdao.list(idx);
        int sum = iBasketdao.sum(idx);
        model.addAttribute("list", list);
        model.addAttribute("sum", sum);
        model.addAttribute("mainPage", "Mypage/cart.jsp");
        return "index";
    }

If you use ajax, I wonder if you have to erase everything you set up on the controller and treat it differently or if you are using ajax. I'm a beginner, so even if I look up the writings about Ajax, I can't understand when I try to apply them to mine. Thank you in advance for your reply.

ajax spring

2022-10-18 09:01

1 Answers

First, fix it with return sum;.

If you call POST/cart_update_plus to AJAX, some number will be answered.

Then JavaScript can receive it and put innerHTML= where the existing quantity was.

If you go in here and look at the example of "change content," which is the same basic key as what you have to do. Read it carefully, understand it, and apply it!


2022-10-18 09:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.