- 정보공유
[JQUERY] 폼을 생성하고 선택된(필요한) 영역의 값만 전송
필요한 영역만 ajax 로 전송 하는 방법.
<form method="post" name="wzfrm" id="wzfrm" action="" onsubmit="return getNext();" autocomplete="off">
<div class="wrap-doc-input">
<div>
<input type="hidden" name="extend_fil_mode[]" class="attach-file-mode" value="1">
<input type="hidden" name="extend_fil_type[]" value="WORD">
</div>
<div>
<input type="hidden" name="extend_fil_mode[]" class="attach-file-mode" value="2">
<input type="hidden" name="extend_fil_type[]" value="PDF">
</div>
<input type="text" name="upload_reason" id="" value="테스트1">
<input type="button" value="전송" class="btn-submit">
</div>
<div class="wrap-doc-input">
<div>
<input type="hidden" name="extend_fil_mode[]" class="attach-file-mode" value="3">
<input type="hidden" name="extend_fil_type[]" value="WORD">
</div>
<div>
<input type="hidden" name="extend_fil_mode[]" class="attach-file-mode" value="4">
<input type="hidden" name="extend_fil_type[]" value="PDF">
</div>
<input type="text" name="upload_reason" id="" value="테스트2">
<input type="button" value="전송" class="btn-submit">
</div>
</form>
<script type="text/javascript">
<!--
jQuery(document).ready(function () {
$(document).on('click', '.btn-submit', function() {
let tmpForm = document.createElement('form');
tmpForm.setAttribute('charset', 'utf-8');
tmpForm.setAttribute('method', 'post');
let formData = new FormData($(tmpForm)[0]);
let $parent = $(this).closest('.wrap-doc-input');
let $inputs = $parent.find('input:hidden, input:text');
$inputs.each(
function() {
formData.append($(this).attr('name'), $(this).val());
}
);
$.ajax({
url: g5_bbs_url+'/test_update.php',
data: formData,
processData: false,
contentType: false,
dataType: 'json',
type:'post',
success:function(req) {
;
}
});
});
});
//-->
</script>