【发布时间】:2023-03-18 07:05:01
【问题描述】:
我想使用 jquery.form 插件上传文件,但该操作不适用于基于输入类型文件的更改功能。
这是代码:
HTML:
<form method='POST' id='upload_image' action='ajax-upload_unpublished_image' enctype='multipart/form-data'>
<input type='file' id='photo_post' name='posting_photo'>
</form>
<div id='#prev'></div>
JS:
$(document).ready(function(){
$('#photo_post').change(function(){
alert('ganti');
$('#upload_image').ajaxForm({
beforeSend: function(){
$('.uu').html('sending');
},
success: function(html){
$('#prev').html(html);
},
error: function(data){
console.log(data);
}
});
});
});
我希望在每次输入更改时上传文件,例如 facebook 上传照片,为什么 ajaxForm 功能不起作用,而如果我使用另一个按钮通过 click 功能执行 ajaxForm 功能,则文件上传。
喜欢:
<button class='upload'>Upload</button>
$('.upload').click(function(){
//do ajaxForm function and it work
});
【问题讨论】:
-
你的网站是什么?
-
不,它还在本地主机中
-
我的意思是那是什么样的网站?
-
@Kermani 分享关于堵车的照片
标签: javascript jquery