I have a form which allow to upload a file in AJAX. It works well, and my progress bar as well. I have 2 questions about my code :
1st : how can i make it compatible with IE 10-
2nd : There is a way to keep the progress when i'm leaving the page ? At time, my progress bar is completing well, but if i leave and return to the page, the progress bar is empty. I would like to keep the progress (eg: my progress bar shows 30%, i leave and return the page after a while, it now shows 55%) ?
My code :
$('#submitfile').click(function(event){
event.preventDefault();
var formData = new FormData($('#form-import-file')[0]);
$.ajax({
url: '{{ path('el_go_to_upload_files') }}',
type: 'POST',
xhr: function() {
var myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){
myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // For handling the progress of the upload
}
return myXhr;
},
beforeSend: beforeSendHandler,
success: completeHandler,
error: errorHandler,
// Form data
data: formData,
//Options to tell jQuery not to process data or worry about content-type.
cache: false,
contentType: false,
processData: false
}
});
// My progress handler
function progressHandlingFunction(e){
if(e.lengthComputable){
$('progress').attr({value:e.loaded,max:e.total});
}
}