2015-6-2 文件的上傳

項目快要結束了,你們都在忙着如何優化本身的代碼,而我還在改着這個重複的bug重複的改javascript

這個的htmlhtml

1   <p><span class="sms-actrl-wd">習題導入:<input type="hidden" id="questionImportFileId"/></span>
2                     <input id="file_name" class="form-select01" style="margin:0px;" type="type" value="" name="file_name">
3                     <a class="tj-btn" href="javascript:document.getElementById('fileToUpload').click();">上傳</a>
4                     <input id="fileToUpload"  type="file"  name="fileToUpload"  class="input" style="display:none"  onchange="ems.chanageFileName();"></p> 
5                      
View Code

這個是jsjava

 1 var filetype="1";
 2 //檢查文件的上傳類型
 3 ems.checkFiletype = function(fileInput){    
 4     if(!/\.(xls)$/.test(fileInput)){
 5         base.popalertOpen({msg:"上傳文件格式不正確1。",title:"操做提示",hasConfirm:true});
 6         filetype="2";
 7         return false;  
 8     }
 9     return true;
10     
11 } 
12 //在輸入框中添加文件的名字
13 ems.chanageFileName = function(){
14     var filename =$("#fileToUpload").val();    
15     $("#file_name").val(filename);    
16 }
17 //上傳excel文件到服務器上
18  ems.submitQuestionService=function (){    
19     if(ems.checkFiletype($("#fileToUpload").val())){
20         //修改樣式
21         $("#ImportMessage").show();
22         $("#Import_false").removeAttr("onclick");
23         $("#Import_true").removeAttr("onclick");
24         //$("#base_close").unbind();
25         $("#Import_true").removeClass('xiugai-btn');
26         $("#Import_false").removeClass('xiugai-btn');
27         
28         $("#Import_true").addClass('tanchu_btn02');
29         $("#Import_false").addClass('tanchu_btn02');
30         //獲取參數
31         var questionFileName = $("#questionFileName").val();    
32         var questionBankId= $("#questionBankId").val();
33         var loginUser = base.getCookie("loginUser");
34         var userAccount = loginUser.userAccount;
35         var domainCode = loginUser.domainCode;            
36         
37         $.ajaxFileUpload({  
38             url : ems.url.question.importFile+"?questionExcelName=" +questionFileName + "&questionBankId=" +questionBankId + "&operatorUserAccount=" +userAccount + "&domainCode=" +domainCode,  //submit to UploadFileServlet  
39             secureuri : false,
40             fileElementId : 'fileToUpload',
41             dataType : 'json', //or json xml whatever you like~  
42             success:function(data){
43                 console.log(data);
44                 var paras ={
45                 title:"操做提示",
46                 msg:data.message,                
47                 hasConfirm:true                    
48                 };                
49                 base.popwinClose();                
50                 base.popalertOpen(paras);            
51                 $("#QuestionTableGrid").datagrid('reload');
52             },  
53             error: function(data, status, e) {
54                 console.log("er11ror");
55                 console.log(data);
56             }  
57         });  
58     }
59     
60 } 

前臺這樣作是沒什麼問題的  要注意ajaxFileUpload中的Datatype如何 返回的數據類型不對應就error方法 還有就是 ajaxFileUpLoad的架包 http://pan.baidu.com/s/1pJ9PPblweb

1  var userAgent = navigator.userAgent.toLowerCase();         
2         jQuery.browser = { 
3             version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1], 
4             safari: /webkit/.test( userAgent ), 
5             opera: /opera/.test( userAgent ), 
6             msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ), 
7             mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent ) 
8         };
View Code

這個在 頁面加載的時候就要加載 增長文件的上傳的瀏覽器兼容性ajax

相關文章
相關標籤/搜索