@ -5,9 +5,7 @@
< title > excel upload< / title >
< / head >
< body >
< form action = "http://localhost:8081/api/cmm/fmcExcelUpload" method = "post"
enctype="multipart/form-data">
< form >
< fieldset >
< legend > 선택< / legend >
< label for = "sysSeCode" > 시스템구분< / label >
@ -23,46 +21,53 @@
< / select > < br / >
< label > 전송일< / label >
< input type = "date" id = "sndngDt" required / > < br / >
< input type = "file" accept = "application/vnd.ms-excel" id = "files" name = "files" required / >
< input type = "file"
accept="application/vnd.ms-excel,
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
id="files" name="files" required/>
< / fieldset >
< button > upload< / button >
< button type = "button" onclick = "handleSubmit()" > upload< / button >
< / form >
< script type = "text/javascript" src = "http://code.jquery.com/jquery-3.4.1.min.js" > < / script >
< script >
const handleSubmit = async (event) => {
event.preventDefault();
const form = event.currentTarget;
function handleSubmit() {
const form = document.querySelector("form");
let sndngDt = document.querySelector("#sndngDt").value.replaceAll("-", "")
let file = document.querySelector("#files").files[0];
if(!sndngDt){
alert('전송일을 선택하세요');
return false;
}
if(!file){
alert('업로드할 파일을 선택하세요');
return false;
}
const fd = new FormData();
fd.append('sysSeCode', document.querySelector("#sysSeCode").value);
fd.append('sndngSeCode', document.querySelector("#sndngSeCode").value);
fd.append('sndngDt', document.querySelector("#sndngDt").value.replaceAll("-", ""));
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();
$.ajax({
url: 'http://localhost:8081/api/biz/cmm/fmcExcelUpload',
data: fd,
cache: false,
contentType: false,
processData: false,
enctype : 'multipart/form-data',
type: 'POST',
success: function(data) {
console.log(data);
alert(JSON.stringify(data.data))
alert(JSON.stringify(data))
} catch (e) {
console.log(res)
alert(JSON.stringify(data));
},
error: function(e) {
console.log(e);
alert(JSON.stringify(e));
}
});
}
const form = document.querySelector('form');
form.addEventListener('submit', handleSubmit);
< / script >
< / body >
< / html >