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.