카테고리 없음

javascript 후기작성

SODAsora 2023. 6. 19. 04:26
/ 후기 작성
export async function writeReview(){

    const urlParams = new URLSearchParams(window.location.search);
    const productId = urlParams.get('product_id');

    const name = document.getElementById("review-title").value;
    const star = document.getElementById("give-star").value;
    const image = document.getElementById("formFile").files[0];
    const content = document.getElementById("review-content").value;
   
   
    const formdata = new FormData();


   
    formdata.append('title', name)
    formdata.append('content', content)
    formdata.append('star', star)
   
    if(image){
        formdata.append('image', image)
    }
   
    for (const pair of formdata.entries()) {
    console.log(pair[0] + ':', pair[1]);
    }
   

    try {
        writeReviewAPI(productId, formdata);
       
    } catch (error) {
        console.error(error);
    }
}