Upload of Ajax without refreshing new files

Source: Internet
Author: User

No nonsense, direct focus:

1: Four JS libraries are required for preparation.

1. jquery 8 or later versions

2. jquery. UI. widget. js

3. jquery. iframe-transport.js.

4. jquery. fileupload. js

Note that references must be done in sequence,

2: HTML must contain an upload tag, which can be copied directly to an HTML file as follows.

<Input id = "fileupload" type = "file" name = "files []" data-url = "@ URL. Action (" Upload "," home ")" multiple>

Data-URL is the upload service path, which can be modified as needed

 

3: Start upload

<script>    $(function () {        $(‘#fileupload‘).fileupload({            dataType: ‘text‘,            add: function (e, data) {                data.context = $(‘<p/>‘).text(‘Uploading...‘).appendTo(document.body);                data.submit();            },            progressall: function (e, data) {                var progress = parseInt(data.loaded / data.total * 100, 10);                $(‘#progress .bar‘).css(                    ‘width‘,                    progress + ‘%‘                );            },            done: function (e, data) {                //$.each(data.result.files, function (index, file) {                $(‘#imgDialog img‘).attr(‘src‘, data.result);                //});                $(img).attr(‘src‘, data.result);            }        });    });</script>

Different parameters indicate different events during the upload process. The code above requires a div with a progress bar.

<Div id = "progress">
<Div class = "bar" style = "width: 0%;"> </div>
</Div>

Upload of Ajax without refreshing new files

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.