2012-10-07 60 views
0

我正在發送附加表單數據以及文件。這裏是表單數據:Uploadify 3.1設置不起作用

  register_object['first_name']=$("#first_name").val(); 
     register_object['last_name']=$("#last_name").val(); 
     register_object['input_email']=$("#input_email").val(); 
     register_object['input_password']=$("#input_password").val(); 
     register_object['repeat_password']=$("#repeat_password").val(); 

而且,以下是我使用uploadify代碼:

 $(document).ready(function(){   
     $("#image_file").uploadify({ 
      'method' : 'post', 
      'queueSizeLimit' : 1, 
      'formData' : JSON.stringify(register_object), 
      'buttonText' : 'Profile Pic', 
      'auto' : false, 
      'multi' : false, 
      'swf' : 'js/plugins/others/uploadify.swf', 
      'uploader' : 'upload.ashx', 
      'fileTypeDesc': 'Image Files', 
      'fileTypeExts': '*.jpg;*.png;*.gif;*.bmp;*.jpeg', 
      'onUploadStart' : function(file) { 
       $('#file_upload').uploadify('settings', 'formData', JSON.stringify(register_object)); 
       alert(JSON.stringify(register_object)); 
      }, 
      'onUploadSuccess' : function(file,data) { 
       alert('The file finished processing. ' + data); 
      }, 
      'onUploadError' : function(file, errorCode, errorMsg, errorString) { 
       alert('The file ' + file.name + ' could not be uploaded: ' + errorString + ' ' + errorMsg); 
      } 
     });    
     $("#register").submit(function(){ 
      $('#input_password').val(CryptoJS.MD5($('#input_password').val())); 
      $('#repeat_password').val(CryptoJS.MD5($('#repeat_password').val())); 
     register_object['first_name']=$("#first_name").val(); 
     register_object['last_name']=$("#last_name").val(); 
     register_object['input_email']=$("#input_email").val(); 
     register_object['input_password']=$("#input_password").val(); 
     register_object['repeat_password']=$("#repeat_password").val(); 
      $("#image_file").uploadify('upload'); 
      return false; 
     }); 
    }); 

當我訪問服務器上的數據後,我什麼也沒得到。

我在做什麼錯?

回答

0

我終於能夠獲得數據到服務器。首先,我必須使用$("#image_file")而不是$("#file_upload")(對不起,我的錯誤)在onUploadStart。其次,我不得不內onUploadStart寫完整的JSON字符串:

$('#image_file').uploadify("settings", "formData", {"first_name":register_object['first_name'],"last_name":register_object['last_name'],"input_email":register_object["input_email"],"input_password":register_object["input_password"],"repeat_password":register_object["repeat_password"]}); 

的代碼是這樣的:

 $(document).ready(function(){   
     $("#image_file").uploadify({ 
      'method' : 'post', 
      'queueSizeLimit' : 1, 
      'formData' : JSON.stringify(register_object), 
      'buttonText' : 'Profile Pic', 
      'auto' : false, 
      'multi' : false, 
      'swf' : 'js/plugins/others/uploadify.swf', 
      'uploader' : 'upload.ashx', 
      'fileTypeDesc': 'Image Files', 
      'fileTypeExts': '*.jpg;*.png;*.gif;*.bmp;*.jpeg', 
      'onUploadStart' : function(file) {    
       **$('#image_file').uploadify("settings", "formData", {"first_name":register_object['first_name'],"last_name":register_object['last_name'],"input_email":register_object["input_email"],"input_password":register_object["input_password"],"repeat_password":register_object["repeat_password"]});** 
       alert(JSON.stringify(register_object)); 
      }, 
      'onUploadSuccess' : function(file,data) { 
       alert('The file finished processing. ' + data); 
      }, 
      'onUploadError' : function(file, errorCode, errorMsg, errorString) { 
       alert('The file ' + file.name + ' could not be uploaded: ' + errorString + ' ' + errorMsg); 
      } 
     });    
     .... 
    });