jQuery file upload ด้วย AJAX บน Semantic UI
ตัวอย่างการเขียน file upload ด้วย jQuery
โดย commit ผ่าน ajax
$(document).ready(function () {
$(":button").click(function(){
var formData = new FormData($("#myform")[0]);
$.ajax({
url : 'http://127.0.0.1/demo/form/submitUpload',
type : 'POST',
data : formData,
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentType
success : function(data) {
console.log(data);
// alert(data);
}
});
});
//กรณีที่เราซ่อน input type file ไว้แล้ว เอา text มารับค่าแทน (เป็นการตกแต่ง)
$(".inp-file").change(function(){
var name=$(this).attr("name");
$('#_'+name).val($(this).val());
});
});
ตัวอย่างเพิ่มเติมพร้อม HTML ตามนี้เลย
jQuery file upload Example