0
你好我的代碼如下我從網上得到我需要移動使用jquery ajax所有字段,而不是文件輸入這裏是PHP頁面圖像的代碼上傳完美的,但其他普通文本輸入不傳遞到服務器端我怎樣才能通過所有表單域使用pekeup圖像上傳
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;
}
嘗試更換'VAR FORMDATA =新FORMDATA();'和'VAR FORMDATA =新FORMDATA(的document.getElementById( 'your_form_id' ));' – Ravi