0

我将连同文件一起发送额外的表单数据。这是表单数据:

         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();

而且,以下是我使用的上传代码:

     $(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;
        });
    });

当我访问服务器上的帖子数据时,我什么也得不到。

我究竟做错了什么?

4

1 回答 1

0

我终于能够将数据发送到服务器。$("#image_file")首先,我不得不$("#file_upload")onUploadStart. 其次,我必须在其中编写完整的 JSON 字符串onUploadStart

$('#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);
            }
         });            
         ....
    });
于 2012-10-07T23:30:52.897 回答