2014-01-23 17 views
1

我使用两个不同的函数上传两个不同类型的文件,并使用ajax。问题是 - >为第一个请求设置的超时也已经设置为其他请求也..因此,如果第一个文件太大,需要将近2分钟上传,然后下一个文件,这是一个非常小尺寸的图像上传通过下一个阿贾克斯请求与不同的时间,也将采取相同的2分钟上传.. 在这里我上传文件直接到亚马逊。在同一页上调用两个JQuery Ajax

下面是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

能否请您解释一下为什么你设置超时,因为ü[R使用两种不同的功能。 –

+0

http://stackoverflow.com/questions/18728004/simultaneous-ajax-calls检查它可能会帮助你。 –

+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?

相关问题