Start upload after choosing a file, using jQuery.

后端 未结 3 1522
醉酒成梦
醉酒成梦 2021-01-31 17:29

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 choos

3条回答
  •  滥情空心
    2021-01-31 18:13

    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/

提交回复
热议问题