fetch formdata를 이용하여 데이터 전송

veloger·2022년 12월 15일
0

코드

목록 보기
4/7
let edit = document.querySelector("#edit");
       edit.addEventListener("submit", (e) => {
          e.preventDefault();        
       		   fetch("/project/write", 
       		      {
       		         method: 'POST',
       		          cache: 'no-cache',
       		          body: new FormData(edit)
       		      })
       		      .then(response => response.json())
       		      .then(jsonResult => {
       		    	 console.log(jsonResult.status);
       		         if(jsonResult.status)
       		        	 alert("업로드 처리 성공");
       		         location.href =  jsonResult.url;
       		         
       		      });
       		});

일일이 json으로 보낼 데이터를 지정하지 않아도 된다.

0개의 댓글