你好我的代码下面我从网上得到我需要移动使用jquery ajax所有字段而不是这里输入的文件是php页面图像的代码上传完美但其他普通文本输入没有传递给服务器端
function UploadFile(){
var error = true;
if (options.theme=="bootstrap"){
var htmlprogress = '<div class="file"><div class="filename"></div><div class="progress progress-striped"><div class="bar pekeup-progress-bar" style="width: 0%;"><span class="badge badge-info"></span></div></div></div>';
}
if (options.theme=="custom"){
var htmlprogress = '<div class="file"><div class="filename"></div><div class="progress-pekeupload"><div class="bar-pekeupload pekeup-progress-bar" style="width: 0%;"><span></span></div></div></div>';
}
obj.next('a').next('div').prepend(htmlprogress);
var formData = new FormData();
formData.append(options.field, obj[0].files[0]);
formData.append('data', options.data);
$.ajax({
url: options.url,
type: 'POST',
data: formData,
// dataType: 'json',
success: function(data){
alert(data)
var percent = 100;
obj.next('a').next('div').find('.pekeup-progress-bar:first').width(percent+'%');
obj.next('a').next('div').find('.pekeup-progress-bar:first').text(percent+"%");
if (data==1){
if (options.multi==false){
obj.attr('disabled','disabled');
}
options.onFileSuccess(file,data);
}
else{
options.onFileError(file,data);
obj.next('a').next('div').find('.file:first').remove();
if((options.theme == "bootstrap")&&(options.showErrorAlerts==true)){
obj.next('a').next('div').prepend('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button> '+data+'</div>');
bootstrapclosenotification();
}
if((options.theme == "custom")&&(options.showErrorAlerts==true)){
obj.next('a').next('div').prepend('<div class="alert-pekeupload"><button type="button" class="close" data-dismiss="alert">×</button> '+data+'</div>');
customclosenotification();
}
error = false;
}
},
xhr: function() { // custom xhr
myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){ // check if upload property exists
myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // for handling the progress of the upload
}
return myXhr;
},
cache: false,
contentType: false,
processData: false
});
return error;
}
答案 0 :(得分:0)
替换
`var formData = new FormData();`
以下
`var formData = new FormData(document.getElementById('put_your_form_id_here'));`
您可以在此处阅读更多内容(浏览使用FormData对象主题发送文件) https://developer.mozilla.org/en-US/docs/Web/Guide/Using_FormData_Objects