chaechae128 / Bakery

0 stars 0 forks source link

결제 #13

Open chaechae128 opened 6 months ago

chaechae128 commented 6 months ago
chaechae128 commented 6 months ago

장바구니에서선택한 상품의 id를 ajax로 보내고model을 통해서 productList와 /order/order-create-view로 이동하기위한 view name도 담았는데 화면이동에 자꾸 실패한다

chaechae128 commented 6 months ago

form 태그로 체크한 값들만 보내면 쉽게 해결 될 일 이였는데 ajax로 하려니까 흐름도 복잡해지고 되게 어려웠었다. @RequestParam(value = "choice") List choice 이렇게 하니까 내가 원하는 값을 다른 페이지에서 서로 주고 받을 수 있다

chaechae128 commented 6 months ago

data-user-name="${user.name}" 이렇게 다른 값들을 데이터로 넣으면 script에서 잘 활용이 되는데 data-user-phoneNumber="${user.phoneNumber}" 로 할 때는 undefined라고 떠서 의아했는데 생각해보니 data는 카멜 케이스로 작성하면 안된다는 것이 떠올랐다 data-user-phone-number="${user.phoneNumber}" 이렇게 고쳐주니 잘 나온다

chaechae128 commented 6 months ago

결제 성공 후에 /order/create에 주문한사람, 주소, 번호, 상품 등등을 ajax로 넘겨야하는데 List productList로 해도 잘 넘어가지 않는다 console에도 잘 찍히는데 data가 계속 넘어가지 않아 400에러가 뜬다...

chaechae128 commented 6 months ago

원래는 이름,, 번호, 주소, 등등을 따로따로 data에 적으려 했다가 List<Map>에다가 다 넣어서 보내려고 시도 했다 하지만 contentType 등 모든걸 계속 수정해도 넘어가질 않는다

chaechae128 commented 6 months ago

$.ajax({ type : http method type, url : url, data : 서버에 전송할 데이터, contentType : "전송할 데이터 타입", //기본 값 : "application / x-www-form-urlencoded; charset = UTF-8"
dataType : '서버로 부터 수신할 데이터 타입', //아무것도 지정하지 않으면 jQuery는 응답의 MIME 유형을 기반으로 해석을 시도 error : 에러 발생시 수행할 함수, success : 성공시 수행할 함수 });

chaechae128 commented 6 months ago

컨트롤러에서는 이렇게 지정해주고 @RequestBody List<Map<String, Object>> list

        $.ajax({
            type: "POST",
            url: "/order/create",
            contentType: 'application/json',
            data: JSON.stringify(list),
            //data:orderList,
            success:function(data){
                alert("성공");
            }
        });

jsp에서는 이렇게 지정해주니까 되었다...