javascript - Start upload after choosing a file, using jQuery. - Stack Overflow

After having chosen a file for upload, I want the file to be uploaded to database without the click of

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
Add a comment  | 

3 Answers 3

Reset to default 39

Assuming 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1737470025a3951209.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信