Try this ...
$(document).ready(function(){
//Traitement du formulaire come_from changement des informations d'introduction
$("#file").submit(function() {
$.ajax({
xhr: function() {
var xhr = new window.XMLHttpRequest();
//upload progress
xhr.upload.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percent = evt.loaded / evt.total;
//upload progress
console.log(percent);
}
}, false);
//download progress
xhr.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percent = evt.loaded / evt.total;
//download progress
console.log(percent);
}
}, false);
return xhr;
},
type: 'POST',
url: "includes/profile_includes/func_infos.php",
data: {
"change_back": " "
},
success: function(data){
alert('done');
}
});
});
});
You can upload simply with jQuery `.ajax()`.
HTML:
<!-- language: lang-html -->
<form id="upload-form">
<div>
<label for="file">File:</label>
<input type="file" id="file" name="file" />
<progress class="progress" value="0" max="100"></progress>
</div>
<hr />
<input type="submit" value="Submit" />
</form>
CSS
<!-- language: lang-css -->
.progress { display: none; }
Javascript:
<!-- language: lang-javascript -->
$(document).ready(function(ev) {
$("#upload-form").on('submit', (function(ev) {
ev.preventDefault();
$.ajax({
xhr: function() {
var progress = $('.progress'),
xhr = $.ajaxSettings.xhr();
progress.show();
xhr.upload.onprogress = function(ev) {
if (ev.lengthComputable) {
var percentComplete = parseInt((ev.loaded / ev.total) * 100);
progress.val(percentComplete);
if (percentComplete === 100) {
progress.hide().val(0);
}
}
};
return xhr;
},
url: 'upload.php',
type: 'POST',
data: new FormData(this),
contentType: false,
cache: false,
processData: false,
success: function(data, status, xhr) {
// ...
},
error: function(xhr, status, error) {
// ...
}
});
}));
});