我使用两个不同的函数上传两个不同类型的文件和ajax。问题是 - >为第一个请求设置的超时也已设置为其他请求..所以如果第一个文件太大并且上传需要将近2分钟,那么下一个文件是一个非常小的图像上传下一个ajax请求与不同的超时也将采取相同的2分钟上传.. 在这里我将文件直接上传到亚马逊。
下面是使用小超时上传我的第二个文件的ajax函数
xhr_request1=$.ajax({
url: 'uploader.php', //server script to process data
type: 'POST',
//Ajax events
beforeSend: function(){beforeSendHandler(fileLoading);},
success: function(response) {completeHandler(response,fileName,fileLoading,filePreview,fileUpload,filename);},
// error: function(xhr,tStatus,err ) {errorHandler(err,fileLoading,filePreview);},
// Form data
data: formData,
//Options to tell JQuery not to process data or worry about content-type
cache: false,
contentType: false,
processData: false,
timeout:50000
});
及以下是上传大文件的下一个功能
xhr_request2=$.ajax({
url: 'contentuploader.php', //server script to process data
type: 'POST',
//Ajax events
beforeSend: function(){beforeSendHandler1(fileLoading1);},
success: function(response) {completeHandler1(response,fileName1,fileLoading1,filePreview1,fileUpload1,filename1);},
// error: function(xhr,tStatus,err ) {errorHandler(err,fileLoading,filePreview);},
// Form data
data: formData,
//Options to tell JQuery not to process data or worry about content-type
cache: false,
contentType: false,
processData: false,
timeout:1000000
});
答案 0 :(得分:0)
您手动将表单数据对象作为所需参数
var fd = new FormData();
fd.append( 'file', input.files[0] );
$.ajax({
url: 'http://example.com/script.php',
data: fd,
processData: false,
contentType: false,
type: 'POST',
success: function(data){
alert(data);
}
});
您可以点击此链接
1.) How to send FormData objects with Ajax-requests in jQuery?