AjaxUpload

AjaxUpload 代码
             < script >
                jQuery(
function (){                    
                    
var  upload  =   new  AjaxUpload(jQuery( ' #test4 ' ), {
                        action: 
' upload-test.php ' ,
                        name: 
' woohoo-custom-name ' ,
                        data: {
                            
' key1 ' " This data won't be sent, we will overwrite it. "
                        },
                        autoSubmit: 
false ,
                        responseType: 
' json ' ,
                        onChange: 
function (file, ext){
                        },
                        onSubmit: 
function (file, ext){
                            
//  Allow only images. You should add security check on the server-side.
                             if  (ext  &&   / ^(jpg|png|jpeg|gif)$ / i.test(ext)) {                            
                                
this .setData({
                                    
' key1 ' ' This should be alerted ' ,
                                    
' key2 ' ' ... '
                                });
                            } 
else  {
                                alert(
' not image ' );
                                
return   false ;
                            }                            
                        },
                        onComplete: 
function (file, response){
                            
this .disable();
                            alert(response.post.key1);
                        }
                    });
                    jQuery(
' #test4upload ' ).click( function (){
                        upload.submit();
                        upload.enable();
                        
return   false ;
                    });
                });                    
            
< / script>

 

 


这样就可以看到选择的文件了。 

    <div style="position:relative;">  
    <input id="fuploadImportExcel" name="fuploadImportExcel" size="30" type="file"  /> 
    <span id="SelectFile" style="position:absolute; top:2px; left:5px; line-height:20px;"></span>
    </div>

 

onChange: function(file,ext) { 

 $("#SelectFile").html(file);

 }, 

 

注: 默认的必须有文件才可以提交。如果文件是选填,则用户没选择文件就不可以提交。 我更新了一下ajaxupload.js

 AjaxUpload代码

 

 

 /Files/myx/js/ajaxupload.rar

你可能感兴趣的:(upload)