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

I was able to finally get the data to the server. Firstly, I had to use $("#image_file") instead of $("#file_upload") (sorry, my mistake) in onUploadStart. And secondly, I had to write complete JSON string within 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"]});

The code goes like this:

     $(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 に答える