@ -5,64 +5,69 @@
< title > excel upload< / title >
< title > excel upload< / title >
< / head >
< / head >
< body >
< body >
< form >
< fieldset >
< legend > 선택< / legend >
< label for = "sysSeCode" > 시스템구분< / label >
< select id = "sysSeCode" >
< option value = "01" > 공영주차장< / option >
< option value = "02" > 장사시설< / option >
< / select > < br / >
< label for = "sndngSeCode" > 발송구분< / label >
< select id = "sndngSeCode" >
< option value = "KKO-MY-DOC" > 카카오< / option >
< option value = "KT-SMS" > 공공알림문자< / option >
< option value = "E-GREEN" > e-그린< / option >
< / select > < br / >
< label > 전송일< / label >
< input type = "date" id = "sndngDt" required / > < br / >
< input type = "file"
accept="application/vnd.ms-excel,
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
id="files" name="files" required/>
< / fieldset >
< button type = "button" onclick = "handleSubmit()" > upload< / button >
< / form >
< form action = "http://localhost:8081/api/cmm/fmcExcelUpload" method = "post"
< script type = "text/javascript" src = "http://code.jquery.com/jquery-3.4.1.min.js" > < / script >
enctype="multipart/form-data">
< script >
< fieldset >
function handleSubmit() {
< legend > 선택< / legend >
const form = document.querySelector("form");
< label for = "sysSeCode" > 시스템구분< / label >
let sndngDt = document.querySelector("#sndngDt").value.replaceAll("-", "")
< select id = "sysSeCode" >
let file = document.querySelector("#files").files[0];
< option value = "01" > 공영주차장< / option >
if(!sndngDt){
< option value = "02" > 장사시설< / option >
alert('전송일을 선택하세요');
< / select > < br / >
return false;
< label for = "sndngSeCode" > 발송구분< / label >
}
< select id = "sndngSeCode" >
if(!file){
< option value = "KKO-MY-DOC" > 카카오< / option >
alert('업로드할 파일을 선택하세요');
< option value = "KT-SMS" > 공공알림문자< / option >
return false;
< option value = "E-GREEN" > e-그린< / option >
}
< / select > < br / >
const fd = new FormData();
< label > 전송일< / label >
fd.append('sysSeCode', document.querySelector("#sysSeCode").value);
< input type = "date" id = "sndngDt" required / > < br / >
fd.append('sndngSeCode', document.querySelector("#sndngSeCode").value);
< input type = "file" accept = "application/vnd.ms-excel" id = "files" name = "files" required / >
fd.append('sndngDt', document.querySelector("#sndngDt").value.replaceAll("-", ""));
fd.append('files', document.querySelector("#files").files[0]);
< / fieldset >
$.ajax({
< button > upload< / button >
url: 'http://localhost:8081/api/biz/cmm/fmcExcelUpload',
data: fd,
< / form >
cache: false,
contentType: false,
< script >
processData: false,
enctype : 'multipart/form-data',
const handleSubmit = async (event) => {
type: 'POST',
event.preventDefault();
success: function(data) {
const form = event.currentTarget;
console.log(data);
alert(JSON.stringify(data));
const fd = new FormData();
},
fd.append('sysSeCode', document.querySelector("#sysSeCode").value);
error: function(e) {
fd.append('sndngSeCode', document.querySelector("#sndngSeCode").value);
console.log(e);
fd.append('sndngDt', document.querySelector("#sndngDt").value.replaceAll("-", ""));
alert(JSON.stringify(e));
fd.append('files', document.querySelector("#files").files[0]);
}
});
const url = form.action;
const res = await fetch(url,
{method: 'post', body: fd}
);
try {
const data = await res.json();
console.log(data);
alert(JSON.stringify(data.data))
alert(JSON.stringify(data))
} catch (e) {
console.log(res)
}
}
}
< / script >
const form = document.querySelector('form');
form.addEventListener('submit', handleSubmit);
< / script >
< / body >
< / body >
< / html >
< / html >