html不用任何控件上传文件

 

 

<form id="myform" action='/upload'  enctype="multipart/form-data">
<input type="file" accept="image/*">
<input type='submit'>
<form>

 

 

//引用jquery
$('#myform').on('sumbit', function(){ var form = $(this); var formdata = false; if (window.FormData){ formdata = new FormData(form[0]); } var formAction = form.attr('action'); $.ajax({ url : '/upload', data : formdata ? formdata : form.serialize(), cache : false, contentType : false, processData : false, type : 'POST', success : function(data, textStatus, jqXHR){ // Callback code } }); });

 

posted @ 2021-06-22 13:35  悠哉大斌  阅读(141)  评论(0编辑  收藏  举报