我正在发送其他表单数据和文件。这是表单数据:
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 :(得分: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);
}
});
....
});