admin管理员组文章数量:1297044
After having chosen a file for upload, I want the file to be uploaded to database without the click of a button. How is this done using jQuery?
I would like to choose a file like this: .gif
<input type="file" valign="baseline" />
After having chosen a file for upload, I want the file to be uploaded to database without the click of a button. How is this done using jQuery?
I would like to choose a file like this: https://i.sstatic.net/0408T.gif
<input type="file" valign="baseline" />
Share
Improve this question
edited Nov 21, 2012 at 10:36
Theo Scholiadis
2,3962 gold badges23 silver badges33 bronze badges
asked Jul 21, 2011 at 9:42
Mehd SMehd S
5832 gold badges10 silver badges21 bronze badges
3 Answers
Reset to default 39Assuming you're using a form:
// select the file input (using a id would be faster)
$('input[type=file]').change(function() {
// select the form and submit
$('form').submit();
});
EDIT: To keep this answer up-to-date:
There is a nice way to upload files via AJAX without hacks described here: http://net.tutsplus.com/tutorials/javascript-ajax/uploading-files-with-ajax/
Use jQuery's plugin uploadify
It's great plugin which has many options, and auto-upload, too
$(document).ready(function() {
$('#file_upload').uploadify({
'uploader' : '/uploadify/uploadify.swf',
'script' : '/uploadify/uploadify.php',
'cancelImg' : '/uploadify/cancel.png',
'folder' : '/uploads',
'auto' : true
});
});
just set the auto to true.. 'auto':true
本文标签: javascriptStart upload after choosing a fileusing jQueryStack Overflow
版权声明:本文标题:javascript - Start upload after choosing a file, using jQuery. - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1737470024a1991397.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论