FormData를 이용한 JQuery Ajax 파일 업로드 샘플
// form 값 전부 보내기
$('.btn_upfile').click(function(){
var idx = $(this).parent().parent().index();
var frm = document.getElementById('frm_store');
frm.method = 'POST';
frm.enctype = 'multipart/form-data';
var fileData = new FormData(frm);
// ajax
$.ajax({
url:'/intra_tmp/backend/image_upload.php',
type:'POST',
data:fileData,
async:false,
cache:false,
contentType:false,
processData:false
}).done(function(response){
alert(response);
});
});
// 필요한 값만 보내기
$('.btn_upfile').click(function(){
var idx = $(this).parent().parent().index();
var frm = document.getElementById('frm_store');
frm.method = 'POST';
frm.enctype = 'multipart/form-data';
var shopNo = frm.shop_No.value;
var files = $('#t_img_manager tr:eq('+idx+') .frm_file')[0].files[0];
var fileData = new FormData();
fileData.append('shopNo', shopNo);
fileData.append(idx, files);
// ajax
$.ajax({
url:'/intra_tmp/backend/image_upload.php',
type:'POST',
data:fileData,
async:false,
cache:false,
contentType:false,
processData:false
}).done(function(response){
alert(response);
});
});