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
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!
910 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
572 Who developed the "avformat-59.dll" that comes with FFmpeg?
571 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
616 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.