- [남군]빛고을총각
- 0
- 44
- 0
- 0
- 2021-08-18 11:29:02
- 관련링크
- 제목 : $.ajax fileupload with formData
<input type="file" name="upfile" id="upfile">
<button id="up">upload </button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$('#up').on('click', function(){
let formData = new FormData();
formData.append('title', 'file upload test with $.ajax');
formData.append('upfile', $('#upfile')[0].files[0]);
let data = [];
formData.forEach(((value, key)=> data[key]= value));
console.log(data);
$.ajax({
url: '/test/regist',
dataType: 'json',
enctype: 'multipart/form-data',
type: 'post',
processData: false, //필수
contentType: false, //필수
data: formData,
success: function(res){},
error: function(err){}
});
});
</script>
- 첨부파일
- 댓글