Ajaxfileupload control user uploads files to the pit

Source: Internet
Author: User

Ajaxfileupload.js is a very convenient upload file control, the use is also simple, combined with jquery use

$.ajaxfileupload ({
"url": "${context}/manage/doctor/adddoctor.htm?doctorname=" + doctorname
+ "&doctortitle=" + doctortitle + "&doctorid=" + Doctorid,
"Secureuri": false,
"Fileelementid": "Filetoupload",
"DataType": "JSON",
"Success": function (data, status) {
if (Data.errorcode = = 0) {
Alert ("Save Success");
} else {

}
},
"Error": function (data, status, E) {
Alert (data.message + "error:" + E);
}
});

Fileelementid is your ID in the HTML code <input type= "File" id= "* *" >

Note that if the return data format you need is JSON, then the backend configured interface returns contenttype must be text/html, I'm using spring MVC, so I added a bean

<bean id= "Handleradapter"
class= "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
<property name= "Messageconverters" >
<list>
<bean
class= "Org.springframework.http.converter.StringHttpMessageConverter" >
<property name= "Supportedmediatypes" >
<list>
<bean class= "Org.springframework.http.MediaType" >
<constructor-arg index= "0" value= "text"/>
<constructor-arg index= "1" value= "html"/>
<constructor-arg index= "2" value= "UTF-8"/>
</bean>
</list>
</property>
</bean>
</list>
</property>
</bean>

Then there is found in the use of <input type= "file" > control, can only use once, the second use of the time, anyway do not trigger the selection button will execute the function, you must refresh the page before you can continue to use, and then the solution is:

$ (document). On (' Change ', ' #fileToUpload ', function () {
var objurl = Getobjecturl (This.files[0]);
alert (Objurl);
if (Objurl) {
$ ("#headPic"). attr ("src", objurl);
}
});


This allows you to reuse the control for file selection. This is written after jquery 1.9, and the old version of jquery uses the live function, which is discarded and replaced with the on function.

Other than that

$ ("#fileToUpload"). On (' Change ', funtion () {

........

});

And

$ ("#fileToUpload"). Change (Funtion () {

........

});

These two kinds of writing, after testing, also ineffective.

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.