[Ajax] Upload file __ajax

Source: Internet
Author: User

First upload file is based on two JS library implementation of JQuery (I used jquery-2.1.4.js) ajaxfileupload.js (there are multiple versions, there may be version bugs)

HTML section

<!--must have the name and id attribute-->
<input id= "imgfile" type= "file" Name= "fil"/>

JS part

$ (document). Ready (function () {/* Note: 1>inpu
            T file must have the name attribute 2>ajaxfileupload datatype must be uppercase or Google browser will not complain
                    *///When file selects $ ("#imgFile"). On (' Change ', function () {$.ajaxfileupload ({
                    URL: ' filecontroller/fileupload ',//For file Upload server-side request address secureuri:false,//Whether a security protocol is required, generally set to False 
                    Fileelementid: ' Imgfile ',//File upload domain ID dataType: ' JSON ',//return value type
                    Success:function (data, status) {//Server Success Response processing function alert (data);
                        }, Error:function (data, status, E) {//server response failure processing function
                    E Exception Information alert (e);
            }
                });
        }); });

Background section

    /**
     * Note: multipartfile must be labeled
     *     @RequestParam ("fil") 
     *     fil is the name of the front-end file]     * * Uploadutil.uploadimg () for the background upload method,
     *     Internal will return JSON data, returned to the picture address *
     * *
    @RequestMapping ("FileUpload") Public
    void FileUpload (HttpServletRequest request, 
            httpservletresponse response,
            @RequestParam (" Fil ") multipartfile file {
        try {
            uploadutil.uploadimg (request, response, file);
        } catch (IOException e) {
            e.printstacktrace ();
        }
    }
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.