Using Jquery.upload.js to implement asynchronous upload sample code _jquery

Source: Internet
Author: User

Related Resources Download: Upload

1:jsp Code:

Import Jquery.upload.js and Jquery-1.7.2.js

Add code to call JS: <a href= "javascript:void (0)" rel= "external nofollow" onclick= "Doupload ()" > Upload </a>

Write at the bottom:

<iframe style= "position:absolute;top:-9999px" src= "<%=basepath%>/resources/upload/upload.htm"/></ Iframe>

2:js Code:

* * File Upload/
function doupload () {//
upload Method
$.upload ({
//upload address
url:window.basepath+ '/reply/ Imageupload ',// 
file domain name
filename: ' uploadfile ',// 
other form data
params: {},
//After uploading, return JSON, text
dataType: ' json ',
//callback before uploading, return true to continue uploading
onsend:function () {return
true;
},
Onsubmit:function () {
},
//After uploading callback
oncomplate:function (data) {
if (data.msg) {

}else{
alert ("Upload image Error!") ");
}
}
});
}

3: Background code:

/** * Picture upload local server * @param request * @param response * @return * * @RequestMapping (value= "I Mageupload ") @ResponseBody public Object imageupload (httpservletrequest request,httpservletresponse response) {Map
<string, object> map=new hashmap<string, object> ();
Uploadutil uploadutil = new Uploadutil (); try {String url = uploadutil.excelupload (request, response);//File Upload} catch (IOException e) {e.printstacktrace ();} Retu
RN map; }

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.