jquery Plugin Ajaxfileupload is used to implement the Ajax file upload, the plug-in is very simple to use, and then write a demo demo How to use the Ajaxfileupload plugin for file upload.
1, introduce the Ajaxfileupload plugin related JS
< script type = "Text/javascript" src = "<%=basepath%>resources/js/jquery-1.2.1.js" ></ script > < script type = "Text/javascript" src = "<%=basepath%>resources/js/ajaxfileupload.js" ></ script >
Note: The test found that ajaxfileupload to the jquery version is required, in the use of Ajaxfileupload and jquery corresponding to the JS version to be consistent, otherwise it will cause an exception, can be downloaded from the ajaxfileupload official website to avoid version conflicts.
2. Implement the Upload function code
Html
<type= "file" name= "Business_licence" ID= " Business_licence " onchange=" upload_image (' business_licence '); " >
JS Processing
//Upload thumbnail image functionUpload_image (upfile_name) {varLoadi = layer.load (' File crosses ... ')); $.ajaxfileupload ({URL:' <{site_url (' upload/index ')}>?file_name= ' +upfile_name, Secureuri:false, Fileelementid:upfile_name, DataType:' JSON ', Success:function(data) {layer.close (Loadi)if(Data.state = = ' SUCCESS ') { $("#" +upfile_name+ "_pic"). Val (Data.url); } Else{layer.msg (data.state,2,-1); return false; } } }); }
jquery Plugin ajaxfileupload for Ajax file uploads