1

I am uploading two different type of file with ajax by using two different function. The problem is->the timeout which is set for the first request has been set for other request also.. so if first file is too large and take almost 2 mins for uploading, then next file which is an image of very small size uploaded by next ajax request with a different time out will be also take same 2 mins for uploading.. here i am uploading file directly to amazon.

Below is the ajax function to upload my second file with a small timeout

    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
            });

and below is next function to upload large files

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
            });
Liath
  • 9,913
  • 9
  • 51
  • 81

1 Answers1

0

you make manually object of form data as your required parameter

    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);
  }
});

You can follow this link
1.) How to send FormData objects with Ajax-requests in jQuery?

Community
  • 1
  • 1
Kushal Suthar
  • 423
  • 6
  • 21